I get the same error with your example, but this works fine (Python 3.6.4):
exec("a = 1")
print(a)
This will print "1". exec("a = 1")
print(a)
This will print "1".But you can do this:
def foo():
exec("a = 1")
return locals()['a']