by quarktasche · 11y ago · 0 comments
def foo():
a = 4
def bar():
print("a = {a}".format(**locals()))
bar()
foo()
which will raise a KeyError, while it will work fine if you add a print(a)
to the end of bar(). def foo():
a = 4
def bar():
a
print("a = {a}".format(**locals()))
bar()
foo()
successfully prints a = 4
which is a bit confusing, but makes sense if you think about it.