闭关修行中......
Regarding the use of exec, the questioner can refer to another question: https://segmentfault.com/q/10...
To give you a solution to your current problem:
# encoding: utf-8 class tess(object): def __init__(self): self.__globals__ = {} self.__locals__ = self.__globals__ def ex(self): sa = 'a=1' exec(sa, self.__globals__, self.__locals__) print(self.__globals__['a']) s = tess() s.ex()
Regarding the use of exec, the questioner can refer to another question: https://segmentfault.com/q/10...
To give you a solution to your current problem: