[Python-Dev] Peculiar import code in pickle.py

Michael Foord fuzzyman at voidspace.org.uk
Tue Jul 13 18:22:24 CEST 2010


On 13/07/2010 16:46, Alexander Belopolsky wrote:
> 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'>
>
> That's what C implementation does AFAICT.
>    

I find the "little dance" much more readable.

All the best,

Michael




> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/fuzzyman%40voidspace.org.uk
>    


-- 
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog

READ CAREFULLY. By accepting and reading this email you agree, on behalf of your employer, to release me from all obligations and waivers arising from any and all NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap, clickwrap, browsewrap, confidentiality, non-disclosure, non-compete and acceptable use policies (”BOGUS AGREEMENTS”) that I have entered into with your employer, its partners, licensors, agents and assigns, in perpetuity, without prejudice to my ongoing rights and privileges. You further represent that you have the authority to release me from any BOGUS AGREEMENTS on behalf of your employer.




More information about the Python-Dev mailing list