exec() works differently in Blender? Found this example on StackExchange:

foo = "bar"
exec(foo + " = 'something else'")
print(bar)


Should print:

something else


Blender (2.73) gives an error that bar is not defined. Can this still be done in Blender?

EDIT: This actually works in a blank file. What doesn't work is:

class testThis():
    def printMe(self):
        foo = "bar"
        exec(foo + " = 'something else'")
        print(bar)

test = testThis()
test.printMe()


Result:

NameError: name 'bar' is not defined


So I'm not sure if it's Blender related.
Official build of Blender come with the latest of Python (3.4.2 as of Blender 2.73); this means that your code cannot compile/be interpreted since, when moving to version 3.0, Python changed print from a keyword to a function.

Your code should be:

foo = "bar"
exec(foo + " = 'something else'")
print(bar) #Print is now a function; must use function call syntax.