[Python-ideas] stealing "var" from javascript

Erick Tryzelaar idadesub at users.sourceforge.net
Thu Apr 10 17:52:33 CEST 2008


On Thu, Apr 10, 2008 at 8:47 AM, Mathias Panzenböck
<grosser.meister.morti at gmx.net> wrote:
> It would also help with local functions!
>
>  def foo():
>     var x = 1
>
>     def bar(y):
>        x += y * 2
>
>     bar(55)

They've added something to py3k to handle this:

def foo():
  x = 1

  def bar(y):
    nonlocal x
    x += y * 2

  bar(55)


More information about the Python-ideas mailing list