Modify the local scope inside a function

Crutcher crutcher at gmail.com
Sun Feb 26 00:00:18 EST 2006


Here you go. Unfortunate that you can't modify locals() easily, but
there are other options.

def foo(d):
  for k in d:
    exec '%s = %s' % (k, repr(d[k]))
  print a + b

foo({'a':1, 'b':2})




More information about the Python-list mailing list