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.
Share
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.
Generator functions and the yield statement.
More consistent use of various types like
listanddict— they can be extended directly.from __future__ import with_statementfrom __future__ import print_functionExceptions are new style classes, and there’s more consistent exception handling. String exceptions have been removed. Attempting to use them raises a TypeError