Fixed bug with string handling for python2.
Replaced file statement with open.
dict.has_key was removed in 3.1, use the in operator instead.