我需要制作一个脚本来调用特定目录中的每个 .py 文件,从而允许被调用脚本访问有关调用脚本的信息(类、变量等)。
所以我有这样的事情:
主文件.py:
class MainClass:
def __init__(self):
self.myVar = "a variable"
for f in os.listdir(path):
if f.endswith(".py"):
execfile(path+f)
def callMe(self):
print self.myVar
myMain = MainClass()
myMain.callMe()
我希望能够在 callee.py 中执行以下操作
myMain.callMe()