Nested function scope problem

Jeremy Sanders jeremy+complangpython at jeremysanders.net
Thu Jul 27 06:45:31 EDT 2006


Gerhard Fiedler wrote:

> Going back to the original question... What would be the most
> common/useful way to access variables from the outer function for writing
> from within the inner function?

I've done something like this (which doesn't look very nice)

def myfunc():

   tok = ['']

   def inner():
       tok[0] += 'hi'
       ...
       tok[0] = 'foo'

   inner()
   print tok[0]

-- 
Jeremy Sanders
http://www.jeremysanders.net/



More information about the Python-list mailing list