Modules that provide differing functionality amongst different Python versions...

holger krekel pyth at devel.trillke.net
Sun Apr 21 14:31:24 EDT 2002


On Sun, Apr 21, 2002 at 02:12:16PM -0400, Carl Banks wrote:
> Allan Crooks wrote:
> > Hi,
> > 
> > I was wondering what the best approach is on providing libraries for
> > varying versions of Python?
> > (...)

> # Import stuff for version 2.1
> if sys.version[:2] >= (2,1):
>     from mymodule2_1 import *
> 
> # Import for version 2.2
> if sys.version[:2] >= (2,2):
>     from mymodule2_2 import *

this solves part of the 'code duplication' problem. Might get a bit tricky
if you just want to define a few additional methods for some classes
(for example 'generator versions' of methods otherwise returning lists).

Ah, and by the way how is

	sys.version[:2] >= (x,y) 

supposed to work? On my python 2.2 

	sys.version[:2] == '2.'   is True

am i missing something here?

	holger





More information about the Python-list mailing list