2011-05-07 64 views
1

我有3个python代码,我想一个接一个地自动调用,以便它们在单次调用中导致最终结果。 如何将这些代码包装到单个脚本中?代码是model-multiple.py,align2d.pymodel-single.py制作一个包含3个python代码的脚本

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 
+3

那些不是“Python代码”,它们是Python(程序)文件。代码是以不明显的方式映射内容和表示的函数。 – phihag 2011-05-07 12:54:46

+0

@海:单词“代码”在英语中有一个以上的含义 – 2011-05-07 13:26:34

回答

2

你有两个选择:

  1. 的快速和肮脏的方式:只需打电话给他们一个又一个shell脚本或在Python脚本(使用systemsubprocess.Popen
  2. 让他们做他们的工作在某些功能,它们导入到一个脚本,并调用每个模块的“做工作”功能
1

您应该考虑以便于从其他脚本和直接调用脚本的方式组织脚本。一般模式是:

def main(): 
    # do all the work 
if __name__ = '__main__': 
    import sys 
    sys.exit(main()) 
2

如果这三个脚本类似于你的榜样,您可以使用后续的Python脚本来运行它们一个接一个:

__import__('model-multiple') 
import align2d 
__import__('model-single') 

__import__是必需的,因为连字符( - )在进口名称中是非法的。如果你愿意重命名脚本:

import model_multiple 
import align2d 
import model_single 
相关问题