Modules that provide differing functionality amongst different Python versions...
holger krekel
pyth at devel.trillke.net
Sun Apr 21 16:38:07 EDT 2002
On Sun, Apr 21, 2002 Carl Banks wrote:
> >> # 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).
>
> I wouldn't say so. It is straightforward enough to add a method to a
> class any time:
>
> >>> class a:
> ... pass
> ...
> >>> def p(self,x):
> ... print "hello, %s" % x
> ...
> >>> a.p = p
> >>> b = a()
> >>> b.p("world")
> hello, world
True. But it splits source-code where you don't really want it to split.
Usually i prefer to keep all object-functions at one place.
> > supposed to work? On my python 2.2
> >
> > sys.version[:2] == '2.' is True
> >
> > am i missing something here?
>
> I just did it how the OP did it, without bothering to check. It
> should be sys.version_info[:2] >= (x,y)
thanks for clarification.
holger
More information about the Python-list
mailing list