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

holger krekel pyth at devel.trillke.net
Mon Apr 22 13:13:13 EDT 2002


On Mon, Apr 22, 2002 at 12:28:39PM -0400, Steve Holden wrote:
> "holger krekel" <pyth at devel.trillke.net> wrote ...
> [ ... ]
> > If so, let me note that "execing a string" is what python does itself.
> > e.g. when you import a module the interpreter is execing a module-string
> or
> > code-object. It's some weird hack but the regular python way.
> >
> Well, there's the minor point that the efficiency of the interpreter's
> regular operation is hugely affected by the pre-compiled ".pyc" file that
> will frequently be created. When you import a module, therefore, usually you
> will be executing a code object.

agreed.

> Writing a module to "exec" one or other of multiple strings gets you pretty
> much the worst of all worlds -- when the (compiled) module is loaded, it
> will be executed as a code object, but then one selected version-specific
> string must still be compiled by an "exec" before being executed each time
> the module is run.

true. Upon first load of the module there is some overhead which 
the use of e.g. generators hopefully make up for :-)

> If some misguided user tries to take advantage of this "portability"
> technique by using the same directory for multiple versions of Python the
> situation gets a whole lot worse, as the ".pyc" files will be re-created
> each time the Python interpreter is different from the one that imported the
> module the last time!

Good point. Installing to the version specific "site-packages" probably helps 
and is not uncommon. After all i presume that most (not all!) modules are not
intended to be used from different python-versions at once. Wrong?

regards,
	holger





More information about the Python-list mailing list