locals().update(...)

eisoab at gmail.com eisoab at gmail.com
Wed Jul 4 13:56:20 CEST 2012



I expected this to work:


def f(**args):
    locals().update(args)
    print locals()
    print a

d=dict(a=1)

f(**d)

but:
> global name 'a' is not defined


Where is my mistake?

This does work:

globals().update({'a':1})

print a

1

-E




More information about the Python-list mailing list