运行 列表的每个元素的外部程序
Run external program to each element of list
我正在尝试为分子列表(SMILES 格式)中的每个元素(分子)调用外部程序 (Openbabel)。但是,我不断收到相同的错误:
/bin/sh: 1: Syntax error: "(" unexpected (expecting ")").
我的代码有什么问题?
from subprocess import call
with open('test_zinc.smi') as f:
smiles = [(line.split())[0] for line in f]
def call_obabel(smi):
for mol in smi:
call('(obabel %s -otxt -s %s -at %s -aa)' % ('fda_approved.fs', mol, '5'), shell=True)
call_obabel(smiles)
subprocess.call
需要可迭代的命令和参数。如果您需要将命令行参数传递给进程,它们属于可迭代对象。也不建议使用 shell=True
,因为它可能存在安全隐患。下面我就省略了。
试试这个:
def call_obabel(smi):
for mol in smi:
cmd = ('obabel', 'fda_approved.fs', '-otxt', '-s', mol, '-at', '5', '-aa')
call(cmd)
我正在尝试为分子列表(SMILES 格式)中的每个元素(分子)调用外部程序 (Openbabel)。但是,我不断收到相同的错误:
/bin/sh: 1: Syntax error: "(" unexpected (expecting ")").
我的代码有什么问题?
from subprocess import call
with open('test_zinc.smi') as f:
smiles = [(line.split())[0] for line in f]
def call_obabel(smi):
for mol in smi:
call('(obabel %s -otxt -s %s -at %s -aa)' % ('fda_approved.fs', mol, '5'), shell=True)
call_obabel(smiles)
subprocess.call
需要可迭代的命令和参数。如果您需要将命令行参数传递给进程,它们属于可迭代对象。也不建议使用 shell=True
,因为它可能存在安全隐患。下面我就省略了。
试试这个:
def call_obabel(smi):
for mol in smi:
cmd = ('obabel', 'fda_approved.fs', '-otxt', '-s', mol, '-at', '5', '-aa')
call(cmd)