如何从python中的上层脚本扫描脚本以获取返回值?

时间:2013-06-26 14:55:46

标签: python return

import os
import pdb

os.system("ToBuildOrNot.py MSS_sims")

for output in os.system:
     if ToBuildOrNot is True:
         print "The MSS_sims Needs To rebuilt"

     elif ToBuildOrNot is False:
         print "The MSS_sism does NOT Need to be Rebuilt"

     else:
         print "error"

1 个答案:

答案 0 :(得分:2)

不要使用系统从Python脚本调用Python脚本,这会产生一个完整的其他解释器。只需导入它。像这样:

import ToBuildOrNot
needsBuild = ToBuildOrNot.run() # or whatever you call your top-level function

由于ToBuildOrNot.py现在是一个脚本,请确保“main”函数受到保护,因此在导入时不会自动执行。大多数人在Python中这样做:What does if __name__ == "__main__": do?