⇤ ← Revision 1 as of 2013-08-09 06:42:05
Size: 986
Comment: Tips for those wishing to create and maintain one Python codebase that works for both Python 2.X and Python 3.Y
|
Size: 990
Comment: Fix headings.
|
Deletions are marked like this. | Additions are marked like this. |
Line 3: | Line 3: |
==Why?== | ==Why?==; |
Line 8: | Line 9: |
==Simple rules for making code work on both 2.X and 3.Y== | ==Simple rules for making code work on both 2.X and 3.Y==; |
Tips for those wishing to create and maintain one Python codebase that works for both Python 2.X and Python 3.Y interpreters (for some value of X and Y).
==Why?==;
Seeing one (very good) rant about how hard it is to use the officially blessed way of using 2to3 reminded me that I also ask users on Rosetta Code to allow code written in a style to work on both versions of Python interchangeably.
I thought we needed some central repository giving tips on how to do this and thought I would start with the rules stated on RC.
==Simple rules for making code work on both 2.X and 3.Y==;
* Use brackets in print statements/functions of one expression. * Use zip and not izip; keys(), values(), items() and not their iter- forms. * Check for raw_input and set raw_input to input if not found. * Conditionally import reduce if it is not found.