setting variables in outer functions

Hrvoje Niksic hniksic at xemacs.org
Mon Oct 29 17:08:45 EDT 2007


Tommy Nordgren <tommy.nordgren at comhem.se> 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:
http://www.python.org/dev/peps/pep-3104/

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