python调用其他目录的python文件

2019-11-01  本文已影响0人  一剑卿心
#test.py

ATLAS_PROCESS_PATH = "../../../../../Resources/GenerateAtlas.py"

def getScriptPath():
    return os.path.dirname(os.path.realpath(sys.argv[0]))

def callCmd(cmd):
    sys.stdout.flush()
    process = subprocess.Popen(cmd, shell = True)
    retCode = process.wait()
    sys.stdout.flush()

    return retCode

def main():
    # 1.Call Generate atlas config.
    print("--Generate atlases config Start.")

    cmdList = ["python"]
    cmdPath = os.path.normpath(os.path.join(getScriptPath(), ATLAS_PROCESS_PATH))
    cmdList.append(cmdPath)
    if len(sys.argv) > 1:
        cmdList.append("-1")
        for i in range(1, len(sys.argv)):
            cmdList.append(sys.argv[i])

    retCode = callCmd(" ".join(cmdList))
    if retCode != 0:
        print("ERROR:Generate atlases list failed")

    print("--Generate atlases config End.")

    time.sleep(3)

上一篇下一篇

猜你喜欢

热点阅读