Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

More Python Goodies... ;o)

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming
View previous topic :: View next topic  
Author Message
Bazza
LXF regular


Joined: Sat Mar 21, 2009 11:16 am
Posts: 1477
Location: Loughborough

PostPosted: Wed Oct 12, 2011 8:27 pm    Post subject: More Python Goodies... ;o) Reply with quote

As many of you guys know I am forever hacking which is why......

I've been quiet-ish for a while because I've been uploading stuff to:-

http://code.activestate.com/recipes/langs/python/

Well I have been experimenting on Backwards Compatibility and this
latest incarnation is being uploaded to LXF first before I decide to release
to the above site...

Inside the code are the previous uploads to the above URL pretaining
to Backwards Compatibility...

Enjoy finding simple solutions to often very difficult probleems...
(Watch out for wordwrapping etc...)

Bazza...

Code:
# 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 sys
if 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)


It's all over to you lot now... ;o)
_________________
73...

Bazza, G0LCU...

Team AMIGA...
Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast