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

Steve Holden sholden at holdenweb.com
Mon Apr 22 12:28:39 EDT 2002


"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.

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.

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!

regards
 Steve
--

home: http://www.holdenweb.com/    book: http://pydish.holdenweb.com/pwp/







More information about the Python-list mailing list