tags:

views:

365

answers:

2

I'm migrating a legacy codebase at work from python 2.4 to python 2.6. This is being done as part of a push to remove the 'legacy' tag and make a maintainable, extensible foundation for active development, so I'm getting a chance to "do things right", including refactoring to use new 2.6 features if that leads to cleaner, more robust code. (I'm already in raptures over the 'with' statement :)). Any good tips for the migration? Best practices, design patterns, etc? I'm mostly a ruby programmer; I've learnt some python 2.4 while working with this code but know nothing about modern python design principles, so feel free to suggest things that you might think are obvious.

+1  A: 

I guess you have already found them, but reference and for others, here are the lists of new features in those two versions:

Apart from picking features from those documents, I suggest using the opportunity (if needed) to make the code conform to the standard Python code style in PEP 8.

There are some automated tools that can help you getting the Python style right: pep8.py implements the PEP 8 checks and pylint gives a larger report that also includes things like undefined variables, unused imports, etc. pyflakes is a smaller and faster pylint.

Martin Geisler
thanks :) yes, i've gone over the new feature list, but without a bit of experience i can't really tell how they translate into bang-for-the-buck. i'm looking for tips from people who've used both 2.4 and 2.6 and discovered what features have made a big difference in their code.
Martin DeMello
Okay, I see -- I'm hacking on Mercurial, and there we've just recently dropped Python 2.3 compatibility. So I'm mostly happy when I use Python 2.4 features :-)I hope someone else can use the links!
Martin Geisler
+4  A: 

Read the Python 3.0 changes. The point of 2.6 is to aim for 3.0.

From 2.4 to 2.6 you gained a lot of things. These are the the most important. I'm making this answer community wiki so other folks can edit it.

  1. Generator functions and the yield statement.

  2. More consistent use of various types like list and dict -- they can be extended directly.

  3. from __future__ import with_statement

  4. from __future__ import print_function

  5. Exceptions are new style classes, and there's more consistent exception handling.

S.Lott