[Tutor] imported module/global
kent37 at tds.net
Sun Apr 15 19:12:49 CEST 2007
Cecilia Alm wrote:
> If a module "x" imports module "y" with a global variable "z", then
> this global can be referred or assigned to in "x" with the syntax
> "y.z" (no "global" keyword preceding) and changes are accessible to
> class methods in "y" referring to "global z".
> I assume this is related to namespace/scope?
I suppose. Python doesn't really have a global scope other than the
builtin scope. What is called global scope is really module scope.
Global variables, functions and classes defined in a module are
attributes of the module object. When you import the module in another
module, you gain access to the imported module's attributes using the
normal dot notation for attribute access.
More information about the Tutor