I\'m having a bit of trouble understanding what\'s going wrong with the following function:
def ness():
pie=\'yum\'
vars()[pie]=4
print vars()[pie]
print yum
vars()
is equivalent to locals()
, which in the case of the function is the local variables in its scope and at in the interactive interpreter at the scope you have it, vars() is globals()
. locals()
is for reading only; the effects of trying to change it are undefined (and in practice, just doesn't work). globals()
can be modified, but you still should never directly put anything in the dict it returns.