Why read-only nested scopes?
Martin v. Löwis
loewis at informatik.hu-berlin.de
Thu Sep 5 06:11:45 EDT 2002
Gonçalo Rodrigues <op73418 at mail.telepac.pt> writes:
> >x = 1
> >
> >def foo():
> > x = 2
> > def bar():
> > x = 3
> > def baz():
> > global x
> > x = 4
> >
> >If you invoke baz(), which of the variables is changed? How do you
> >denote that you want to change the others?
>
> I think that crawling up the scope hierarchy and stopping at the first x
> that one finds (in the above case, the one defined in bar) is a sensible
> solution.
This solution is not backwards-compatible. global always refers to
globals(), programs may rely on that.
Regards,
Martin
More information about the Python-list
mailing list