import overwrites __name__

Stephen Hansen apt.shansen at
Fri May 8 18:08:03 EDT 2009

> Still I appreciate if someone could explain me why.

We can't without seeing the code. There shouldn't be any difference, so if
there is then its because your code is doing something to cause it-- break
it down to a runnable example and we may be able to tell you why, giving us
real code and real errors / output. When you distill it into a pseudocode
explanation of what you're doing and ask why it doesn't work, quite often
what you end up doing is unintentionally leaving out the cause.

E.g., I made two files;
    my_name = __name__
    print my_name
    print len(dir())
    from other import y as z
    print __name__
    print len(dir())
    print my_name
    y = True

And the output is -- no matter if there's a pyc or not -- always:

There's nothing in default/standard Python which is causing this behavior--
Python doesn't run code differently based on if there's a pyc or not or if
its generating a pyc or not, not by itself. You have to be doing something
which is goofying up the interpreter somewhere. Not sure what, but it has to
be in that 'x' you're importing from :)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list