Python 3 compatibility fix

I've fixed compatibility issues with Python 3. Tested on Python 2.7.3 and Python 3.2.3
Please let me know if You want merge it @crucialfelix