Modules that provide differing functionality amongst different Python versions...
Bengt Richter
bokr at oz.net
Sun Apr 21 16:52:43 EDT 2002
On Sun, 21 Apr 2002 20:31:24 +0200, holger krekel <pyth at devel.trillke.net> wrote:
>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 *
>
Wouldn't you want to import from 2.2 first (and perhaps use elifs)?
(though obviously the if-tests themselves must be lowest-version compatible
if done in that order).
>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
>
>
He probably meant
>>> sys.version_info
(2, 2, 0, 'final', 0)
>>> sys.version_info[:2]
(2, 2)
Although 1.5.2 doesn't have this AFAIK, so
>>> import sys, string
>>> string.split(sys.version)[0] >= '2.2'
1
where
>>> string.split(sys.version)[0]
'2.2'
might be a better idea.
Regards,
Bengt Richter
More information about the Python-list
mailing list