Trouble accessing global vars

Alex Martelli aleaxit at yahoo.com
Mon Sep 6 03:27:49 EDT 2004


Troels Therkelsen <t_therkelsen at hotmail.com> wrote:
   ...
> If you want to modify a global variable from inside a function/method scope,
> you need explicitly tell Python that this is indeed your wish, by using the
> global keyword, like this:

_MODIFY_ (call a method that performs modification on a mutable object)
would be no problem.  (bind or) _REBIND_ a global name, that's the
troublespot where 'global' is needed.  The += operator, like any other
assignment, REBINDS the name (even when the object is mutable, so the
change is in-place, nevertheless the name-rebinding occurs, for
uniformity AND since that must be determined by the compiler which can't
rely on knowing the object type).


Alex



More information about the Python-list mailing list