[Python-Dev] unexpected import behaviour

Michael Foord fuzzyman at voidspace.org.uk
Fri Jul 30 19:32:10 CEST 2010


On 30/07/2010 17:59, Oleg Broytman wrote:
> On Fri, Jul 30, 2010 at 07:26:26AM +0100, Daniel Waterworth wrote:
>    
>> @Oleg: ...
>> This is purely CPython bug-fixing/the discussion of
>> implementation choices.
>>      
>     I am not sure it's a bug.

It isn't a bug but it's a very common *cause* of bugs, even for 
relatively experienced Python programmers (this exchange being another 
case in point).

Michael

> By manipulating sys.path (or symlinks in the
> FS) one can import the same file as different modules as many times as
> [s]he wants. Should this be fixed for __main__? I doubt it. Instead of
> making __main__ a special case follow the rule: don't import the same
> module under different paths/names.
>     Make your script simply
>
> from test import main
> main()
>
> Oleg.
>    


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