class Foo(object):
def __init__(self, x):
self.bar(x=x)
def bar(self, **kwargs):
print kwargs
locals().update(kwargs)
print x
f = Foo(12)
this seems obvious, but it doesn't work, the first print would output {'x': 12}
, which is correct, however, then I get this error: NameError: global name 'x' is not defined
Why would this happen? thanks.