[Python-Dev] Python FAQ: Why doesn't Python have a "with" statement?

Phillip J. Eby pje at telecommunity.com
Sat Jun 14 16:43:46 CEST 2008


At 08:19 AM 6/14/2008 +0200, Cesare Di Mauro wrote:
>Assignament must work on the object's namespace, of course:
>
>def foo(a):
>   on a:
>      x += 1
>      print x
>     will be equivalent to:
>
>def foo(a):
>   a.x += 1
>   print a.x

Er, you need a syntactic disambiguation here to distinguish 
attributes from locals or globals:

def foo(a):
   on a:
      .x += 1
      print .x

Otherwise, this leads to all sorts of craziness.  You'd also have to 
restrict what could be referenced in a nested "on" block, in order to 
avoid further ambiguities.



More information about the Python-Dev mailing list