Differences between revisions 1 and 2
Revision 1 as of 2013-08-09 06:42:05
Size: 986
Editor: paddy3118
Comment: Tips for those wishing to create and maintain one Python codebase that works for both Python 2.X and Python 3.Y
Revision 2 as of 2013-08-09 06:51:02
Size: 990
Editor: paddy3118
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.

2and3 One codebase for dual version support (last edited 2013-08-09 06:56:37 by paddy3118)

Unable to edit the page? See the FrontPage for instructions.