Exec函数
exec('var%d=%d'%(1,1))
print(var1)
命名空间字典
locals()['var2'] = 2
print(var2)
类中字典
class varclass:
def __init__(self):
self.__dict__['var3'] = 3
print(self.var3)
varclass()
exec('var%d=%d'%(1,1))
print(var1)
locals()['var2'] = 2
print(var2)
class varclass:
def __init__(self):
self.__dict__['var3'] = 3
print(self.var3)
varclass()