编写一个脚本包装3个python代码

2024-05-13 11:49:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我有3个python代码,我想一个接一个地自动调用,这样它们就可以在s单次调用中得到最终结果。 如何将这些代码包装成单个脚本?代码是model-multiple.pyalign2d.pymodel-single.py。在

型号-多个.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

Tags: oftheto代码frompyimportenv
3条回答

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

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

您有两种选择:

  1. 快速而肮脏的方法:在shell脚本或Python脚本中逐个调用它们(使用system或{})
  2. 让它们在某个函数中工作,将它们导入到单个脚本中,并调用每个模块的“do work”函数

如果这三个脚本都与您的示例相似,则可以使用下面的Python脚本逐个运行它们:

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

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

^{pr2}$

相关问题 更多 >