Modules that provide differing functionality amongst different Python versions...
Carl Banks
imbosol at vt.edu
Sun Apr 21 14:12:16 EDT 2002
Allan Crooks wrote:
> Hi,
>
> I was wondering what the best approach is on providing libraries for
> varying versions of Python?
>
> My aim is to distribute a module that will provide a set of core
> functions, but provide more functions to later versions of Python.
>
> For example, I make a module that works on 2.0, but if used on 2.1,
> will provide more functions to say, do with the warning framework. If
> used on 2.2, certain functions that return lists in earlier versions
> of Python, will use generators instead.
>
> Rather than keeping several versions of the same module (but for use
> with different versions of Python), I was wondering if there was a
> more elegant solution?
# mymodule.py
"Does different stuff depending on what version is used."
# Stuff common to all versions goes here
# 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 *
You still have to use several modules, but you don't have to maintain
multiple copies of code common to all the modules, and the same files
work with any version.
--
CARL BANKS http://www.aerojockey.com
"Nullum mihi placet tamquam provocatio magna. Hoc ex eis non est."
More information about the Python-list
mailing list