To make HasyUtils compliant with Python2 and Python3, these changes had to be done, see below. The additions made by Pablo Bereciartua Perez are acknowledged.
print "..." -> print( "...") print "..." % a -> print( "..." % a) print _sys.exc_info()[0] -> print(_sys.exc_info()[0]) print repr(e) -> print( repr( e)) print "...", -> sys.stdout.write( "...") sys.stdout.flush() except Exception, e: -> except Exception as e raise ValueError, 'bad value' -> raise ValueError( 'bad value') a in hsh.keys() -> a in list( hsh.keys()) hsh.has_key( kName) -> kName in hsh iterator.next() -> next( iterator) 0777 -> 0o777 izip( a, b) -> list(zip( a, b)) sys.exitfunc = exitHndlr -> import atexit atexit.register(exitHndlr) import TgUtils -> from . import TgUtils from p10 import * -> from .p10 import * import thread -> import _thread import __builtin__ -> import builtins from OtherUtils import * -> from HasyUtils.OtherUtils import * hsh.iteritems() -> hsh.items() os.write( fh, 'abc') -> if sys.version.split( '.')[0] == '3': os.write( fh, bytes( 'abc', 'utf-8')) exec is a statement -> exec() is a function, does not change local variables workaround, e.g. (from VmExecutor.py): nameSpace = {} exec( "from veryTrivial import VM", nameSpace) self.vm = nameSpace[ 'VM']() msg = json.dumps( hsh) -> msg = json.dumps( hsh) sckt.send( msg) sckt.send( bytearray( msg, encoding="utf-8")) 3/2 is 1 -> 3/2 is 1.5 a = input( "number") -> a = input( "number") creates an int creates a string range(3) -> list( range( 3)) sorted( cmp=...) -> sortedListOfDcts = sorted( listOfDcts, key=lambda k: k['name'])