import overwrites __name__

Stephen Hansen apt.shansen at gmail.com
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;

main.py
    my_name = __name__
    print my_name
    print len(dir())
    from other import y as z
    print __name__
    print len(dir())
    print my_name
other.py:
    y = True

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

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

--S
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090508/e28fc521/attachment-0001.html>


More information about the Python-list mailing list