setting variables in outer functions

Hrvoje Niksic hniksic at
Mon Oct 29 22:08:45 CET 2007

Tommy Nordgren <tommy.nordgren at> writes:

> Given the following:
> def outer(arg)
>      avar = ''
>      def inner1(arg2)
>           # How can I set 'avar' here ?

I don't think you can, until Python 3:

Currently the (ugly) solution is to change variable assignment to
object mutation:

def outer(arg)
     avar = ['']
     # use avar[0] where you'd normally use avar
     def inner1(arg2)
          # modify the value of avar by setting avar[0]

More information about the Python-list mailing list