import overwrites __name__

Marco marco.mandl at gmx.at
Fri May 8 17:15:00 EDT 2009


Marco wrote:

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


I just discovered the .pyc file for the main module is not created. When I 
delete the old pyc and import the main module from the python shell it works 
fine. But when I start it with "python main_module.py" the .pyc is not 
created and it happens as shown above.

So what leads to the behavior that the .pyc is not created?

br
Marco





More information about the Python-list mailing list