0
我需要制作一个脚本来调用特定目录中的每个.py文件,从而允许被调用脚本访问有关调用脚本的信息(类,变量等)。Python脚本调用其他Python脚本
所以我有这样的事情:
mainfile.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()
我很好奇为什么你不使用导入,然后从这些文件创建实例? –
@WissamYoussef - 我需要主脚本作为主程序。其他脚本就像插件。有没有办法做到这一点? – functorial
你来自Java吗? – reem