import overwrites __name__

Marco marco.mandl at gmx.at
Fri May 8 13:14:52 EDT 2009


Hi,

There happened something that I do not understand. Actually I don't even 
know how it can be possible.

I import a module and then the name space of the importing module seems do 
be overwritten.

my_name = __name__
print my_name
print len(dir())
from x import y as z
print __name__
print len(dir())
print my_name

->
__main__
119
x
117
unhandled NameError "name 'my_name' is not defined"

The module x is from me, and I am not aware of doing anything cruel there. 
What evil thing can be done in its sub module that can result in that 
strange thing?

br
Marco





More information about the Python-list mailing list