You don't need to use exec
for this, as the other answers show, but here is the problem with your original code:
for char in uppercase:
exec "%s = %s" % (char, Variable(str(char))) in None
This will exec A = A
, B = B
, etc. While this may be interesting if you're an ardent follower of Objectivism, python won't care too much for it.
You want to have the Variable()
stuff inside the exec for it to matter:
for char in uppercase:
exec "%s = Variable('%s')" % (char, char)
In the future, if you're trying to use exec
, first try not to. Second, print what you're execing -- that will help to debug.