namespace & imported modules

Peter Otten __peter__ at web.de
Wed Nov 24 03:10:59 EST 2004


Jason wrote:

> I've been having trouble understanding the difference between global
> namespace within and between modules.  For example, I can program a

Did you know that global variables are only global to the module?

> from subfile import thread1, thread2        # this should be the only

This will bind the names thread1 and thread2 in the importing module, i. e.
you have now two distinct thread1 variables no longer pointing to the same
object after a thread1 = something assignment in one of the modules. Do 

import subfile

instead and access the variables with qualified names

subfile.thread1 = something

in all modules except subfile.py, and everything should be OK.

Peter




More information about the Python-list mailing list