Incomplete draft: Namespaces
Bengt Richter
bokr at oz.net
Sun Apr 7 07:00:34 EDT 2002
On Sun, 07 Apr 2002 10:17:08 +0200, Just van Rossum <just at xs4all.nl> wrote:
>In article <a8nric$sbb$1 at panix1.panix.com>, aahz at pythoncraft.com (Aahz)
>wrote:
>
>> The three execution scopes are function local (hereafter referred to as
>> local), module global (hereafter referred to as global), and builtin
>> scope. Local scope exists any time Python's instruction pointer is
>> inside a function/method. Global scope refers to the currently
>> executing module; explicitly accessing a function in another module
>> through attributes changes the current module:
>>
>> from M import f
>> f() # f()'s global scope is the current module
>> import M
>> M.f() # f()'s global scope is now the module M
>
>No: f()'s global scope is always module M. Scoping is static after all.
>Or are you saying something different?
>
>Just
+---< M.py >---
|a='a bound in M.py'
|def f(): return a
+--------------
>>> import M
>>> M.__file__
'M.py'
>>> M.f()
'a bound in M.py'
>>> a='a bound interactively'
>>> M.f()
'a bound in M.py'
>>> from M import f
>>> f()
'a bound in M.py'
>>> f2=M.f
>>> f2()
'a bound in M.py'
>>> a
'a bound interactively'
Regards,
Bengt Richter
More information about the Python-list
mailing list