Why read-only nested scopes?

Martin v. Löwis loewis at informatik.hu-berlin.de
Wed Sep 4 14:38:30 EDT 2002


Gonçalo Rodrigues <op73418 at mail.telepac.pt> writes:

> >Gonçalo Rodrigues <op73418 at mail.telepac.pt> writes:
> >
> >> So why hasn't this been extended when nested scopes were introduced,
> >> e.g. by reusing the global directive or some other one? 
> >
> >I think the main reason is that nobody could propose an acceptable
> >syntax. Reusing the global directive does not work.
> 
> Can you explain why it does not work?

Consider

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?

Regards,
Martin




More information about the Python-list mailing list