Writing backwards compatible code

Dave Brueck dave at pythonapocrypha.com
Fri Apr 14 14:32:50 EDT 2006


Steven D'Aprano wrote:
> I came across an interesting (as in the Chinese curse) problem today. I
> had to modify a piece of code using generator expressions written with
> Python 2.4 in mind to run under version 2.3, but I wanted the code to
> continue to use the generator expression if possible.
[snip]
> What techniques do others use?

About the only reliable one I know of is to not use syntax from the newer 
version, period, if the code needs to run on old versions. Your example was 
pretty straightforward, but unless the use case is always that simple it's too 
easy to have two separate versions of the code to maintain, and there's no way 
to enforce that changes/fixes to one will be duplicated in the other.

So... if you have to take the time to make one that works with the older 
version, you might as well just use it exclusively.

-Dave



More information about the Python-list mailing list