On Tue, Jul 13, 2010 at 1:57 PM, Benjamin Peterson <benja...@python.org> wrote:
> 2010/7/13 Alexander Belopolsky <alexander.belopol...@gmail.com>:
>> On Tue, Jul 13, 2010 at 11:34 AM, Antoine Pitrou <solip...@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.import_module 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
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to