我有3个python代码,我想一个接一个地自动调用,这样它们就会导致单个调用的最后一个。
如何将这些代码包装成单个脚本?代码为model-multiple.py
,align2d.py
,model-single.py
。
model-multiple.py是
from modeller import * # Load standard Modeller classes
from modeller.automodel import * # Load the automodel class
log.verbose() # request verbose output
env = environ() # create a new MODELLER environment to build this model in
env.io.atom_files_directory = ['.', '../atom_files']
a = automodel(env,
alnfile = '3NTD_align.ali', # alignment filename
knowns = ('3NTDA'),
sequence = 'target', # code of the target
assess_methods=(assess.DOPE, assess.GA341,assess.normalized_dope))
a.starting_model= 1 # index of the first model
a.ending_model = 1 # index of the last model
# (determines how many models to calculate)
a.make() # do the actual homology modeling
答案 0 :(得分:2)
您有两种选择:
system
或subprocess.Popen
)答案 1 :(得分:2)
如果所有三个脚本都与您的示例相似,则可以使用以下Python脚本依次运行它们:
__import__('model-multiple')
import align2d
__import__('model-single')
__import__
是必需的,因为连字符( - )在导入名称中是非法的。如果您愿意重命名脚本:
import model_multiple
import align2d
import model_single
答案 2 :(得分:1)
您应该考虑以便于从其他程序和直接调用这两种方式来组织脚本。一般模式是:
def main():
# do all the work
if __name__ = '__main__':
import sys
sys.exit(main())