Namespacedifference reading - writing ??

Steven Taschuk staschuk at telusplanet.net
Fri Jun 27 15:36:01 CEST 2003


Quoth Peter Abel:
  [...]
> Is there really a difference in namespacehandling depending
> on writing or reading variables?

Yes.  Assigned-to variables are local; variables merely referred
to may be found in nested scopes.

    "When a name is used in a code block, it is resolved using the
    nearest enclosing scope. [...] If a name is bound in a block, it
    is a local variable of that block. [...] If a name binding
    operation occurs anywhere within a code block, all uses of the
    name within the block are treated as references to the current
    block. [...] The local variables of a code block can be determined
    by scanning the entire text of the block for name binding
    operations."
                <http://www.python.org/doc/current/ref/naming.html>

(Note that defs and whatnot are also name-binding operations.)

-- 
Steven Taschuk                                                   w_w
staschuk at telusplanet.net                                      ,-= U
                                                               1 1





More information about the Python-list mailing list