Incomplete draft: Namespaces

Aahz aahz at pythoncraft.com
Sun Apr 7 10:52:48 EDT 2002


In article <just-16031B.10170807042002 at news1.xs4all.nl>,
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?

Okay, here's the new version:

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; functions defined in another module still consider
that module their global scope even if imported into the current module's
namespace:

    import M
    M.f()               # f()'s global scope is the module M
    from M import f
    f()                 # f()'s global scope is still M
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"There are times when effort is important and necessary, but this should
not be taken as any kind of moral imperative."  --jdecker



More information about the Python-list mailing list