[Python-Dev] Peculiar import code in pickle.py (original) (raw)

Jack Diederich jackdied at gmail.com
Tue Jul 13 20:10:50 CEST 2010


On Tue, Jul 13, 2010 at 1:57 PM, Benjamin Peterson <benjamin at python.org> wrote:

2010/7/13 Alexander Belopolsky <alexander.belopolsky at gmail.com>:

On Tue, Jul 13, 2010 at 11:34 AM, Antoine Pitrou <solipsis at pitrou.net> wrote:

On Tue, 13 Jul 2010 11:25:23 -0400 .. Only for top-level modules:

import("distutils.core", level=0) <module 'distutils' from_ _'/home/antoine/py3k/_svn_/Lib/distutils/_init_.py'> sys.modules["distutils.core"] <module 'distutils.core' from_ _'/home/antoine/py3k/_svn_/Lib/distutils/core.py'> That's right, but I believe the recommended way to achieve that behavior is to supply a dummy fromlist: import("distutils.core", fromlist=["dummy"], level=0) <module 'distutils.core' from_ _'/Users/sasha/Work/python-svn/py3k/Lib/distutils/core.py'> No! That's not recommended and a complete hack. The "dance" or importlib.importmodule is preferred.

A complete hack with a long pedigree: module = import(modname, None, None, 'python2.4 is silly, revisit this line in 2.5')

I think that line in a code base of mine didn't get altered until 2.6.something.

Hack-ily,

-Jack



More information about the Python-Dev mailing list