newbie - Scoping question

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Mon Sep 17 19:35:53 CEST 2001


17 Sep 2001 08:59:13 -0700, P Adhia <padhia at yahoo.com> pisze:

> I am confused as to why "x", when not qualified with module name, does
> not refer to "x" in "test", even though I did "from test import *".

"from test import *" imports a module and injects a snapshot of the
module's namespace into the current namespace. Names in the current
namespace are then ordinary variables, bound to the same objects to
which the module has bound its variables at the time of the import,
but independent from the module. Further changes to the module's
namespace don't affect the current namespace, nor vice versa. It's
the same as if you did
    import test
    x = test.x
    get_x = test.x
    set_x = test.x
    del test
Now x and test.x are different variables referring to the same object.

-- 
 __("<  Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^                      SYGNATURA ZASTĘPCZA
QRCZAK



More information about the Python-list mailing list