variable scoping across imports?

Fredrik Lundh fredrik at pythonware.com
Sat Dec 1 20:25:47 EST 2001


Kragen Sitaker wrote:
> Hans Nowak <wurmy at earthlink.net> writes:
> > Let's see... you start x.py... x imports y... y imports x again...
> > at that moment x.z0 is None. Now y has a copy of x's namespace with
> > z0 == None. This is, however, not the same as the global namespace
> > you're currently in. set() changes z0 to 33, but it does *not*
> > affect the x module that was imported by y.
>
> I don't think things work this way, actually

assuming Hans meant to write "reference to" instead
of "copy of", it does work that way.

when you run "python x.py", that script runs in the
__main__ namespace.

the "set" function sets __main__.z0 to 33, but that's
not what the y module is printing.

more here:

    http://effbot.org/guides/import-confusion.htm

</F>





More information about the Python-list mailing list