# compatibility5.py## Backwards compatibility for text mode Python 1.4.0 to 3.2.2...# Some simple things that work for all these versions on the# classic AMIGA, E-UAE, PCLinuxOS 2009, Debian 6.0.0, Windows XP and# Vista and WinUAE. Note, classic AMIGAs and derivatives only reach# Python version 2.4.6. AROS goes to version 2.5.2.# Python versions checked against, 1.4.0, 2.0.1, 2.4.2, 2.5.2, 2.6.1# 2.6.6, 2.7.2, 3.0.1, 3.1.3 and 3.2.2.# Versions 1.4.0 to 2.7.2 have these already so running this code just# imports "sys" only and therefore no harm is done...## (C)2011, B.Walker, G0LCU. Initially issued to LXF as Public Domain.# You may do with the code as you please.## These are to go along with these pointers...# http://code.activestate.com/recipes/577836-raw_input-for-all-versions-of-python/?in=lang-python# http://code.activestate.com/recipes/577868-backwards-compatibility/?in=lang-python# http://code.activestate.com/recipes/577872-bacwards-compatibility-part-2/?in=lang-python# http://code.activestate.com/recipes/577884-backwards-compatibility-part-3/?in=lang-python# http://code.activestate.com/recipes/577903-backwards-compatibility-part-4/?in=lang-python# ===================================================================# Single old functions to make Python backwards compatible... ;o)# These are a little "tongue in cheek" but enjoy...# To add to an existing Python 3.x.x run, type:-## >>> exec(open('/path/to/file/compatibility5.py').read())<RETURN/ENTER>## And away you go...import sysif sys.version[0]=="3": # The line "raw_input=input" is already in the first URL... # IMPORTANT NOTE:- If you use, for versions 1.4.0 to 2.7.2, # input=raw_input then that _removes_ the genuine "input()" # function from the __builtins__ until Python is re-run. # THUS you are then forced to add the "eval()" function if you # require the original "input()" functionality... Good eh! ;o) raw_input=input # "xrange()" is back... xrange=range # These functions, deleted from Version 3.x.x, are now back too... def execfile(STRING_some_path_and_file, globals={}, locals={}): exec(open(STRING_some_path_and_file).read()) in globals, locals def reload(some_module): import imp imp.reload(some_module) return(some_module) def coerce(x,y): if str(type(x))=="<class 'float'>" or str(type(y))=="<class 'float'>": x=float(x) y=float(y) else: x=int(x) y=int(y) return(x,y)# ===================================================================# There will be more to follow...# Enjoy finding simple solutions to often very difficult problems... ;o)