Modify for python 3 support

Tracker item 3733.