Wednesday, June 26, 2013

Spatial Data for Mars

The geo-geek in me thinks this is cool, and you should too.  Here is a link to grab all sorts of geo-spatial data for Mars.



Enjoy

Friday, June 21, 2013

Convert time Object to datetime Objects

Here is a quick snippet to convert a time object to a datetime object.

import time
import datetime
gmt_time_object = time.gmtime()
dt = datetime.datetime.fromtimestamp(time.mktime(gmt_time_object))

Now you have a datetime object from a time object.
Enjoy

Friday, June 7, 2013

Merging Python Dictionaries

Sometimes you need to merge two dictionaries into one, and here is a pythonic way of doing it:

>>> x = {'key1': 34, 'key2': 35}
>>> y = {'key3':36', 'key4': 36}
>>> z = x.copy() 
>>> z.update(y)
>>> print z
{'key1': 34, 'key2': 35, 'key3': 36, 'key4': 36}

This method copies the x dictionary into a new set of memory.  This needs to be done because just assigning to a new variable say z = x will reference the same block of memory thus when you update q, you will update dictionary x as well, and we do not want that.  So copy() allocates a new set of memory blocks, puts the information into those blocks, then update() will add the additional keys from an existing dictionary.

It's very simple, and the pythonic way.  (The pythonic way is sort of like the force, but you can move things with your mind or alter thoughts, or do parlor tricks... so it's not like the Force at all)

Enjoy