0

我需要制作一个脚本来调用特定目录中的每个 .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()
4

1 回答 1

0

怎么用os.sytem

for f in os.listdir(path):
    if f.endswith(".py"):
        os.system(path+f)
于 2013-10-21T03:32:37.987 回答