Python子进程变量类型?

2024-09-29 23:20:52 发布

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

我正在编写一个python代码,它使用一些只能从Unix终端访问的程序(windows7操作系统,使用putty终端)我已经看过无数篇文章,我知道有人问过类似的问题,但没有什么对我有用。在

这是密码

#written in Py 2.7

from subprocess import call

subject = open ('test_file1', 'r')
target =open ('test_file2', 'r')
output = open ('output_test.bla8', 'w')
call(['blat', '-prot', '-minScore=0', '-stepSize=5', '-repMatch=2253', '-minIdentity=0', '-out=blast8', subject, target, output])
subject.close()
target.close()
output.close()

我收到的错误是:

^{pr2}$

解释一下,“blat”是我调用的程序,所有的-标志都是我想传递给blat程序的参数,最后三个语句也是我需要进入程序的参数,但它们实际上指定了程序读/写的文件。在

如果不使用'subprocess.call'?? 当然,有一个简单的方法可以做到这一点,这是我作为初学者所不知道的。顺便说一下,我已经浏览了子流程文档,但是作为一个新手,我仍然不能完全理解http://docs.python.org/2/library/subprocess.html#subprocess.call

谢谢!!!在


Tags: 代码test程序终端targetcloseoutput参数
2条回答

我用这个代码解决了这个问题:

new_list= []
for file in os.listdir('.'):
    if fnmatch.fnmatch(file, '*.fa'):
    new_list.append(file)

input_file1 = new_list[0]
input_file2 = new_list[1]
blat =call(['blat', '-prot', '-minScore=0', '-stepSize=5', '-repMatch=2253', 'minIdentity=0', '-out=blast8', input_file1 , input_file1, 'output_test'])

当您这样做时:

f = open('file','r')

Python进程正在打开文件并将文件句柄/对象存储在f中。此打开的文件句柄/对象不能放在命令行上(您不能键入它),因此您从call中得到一个错误,它接受命令行参数。

{blat2>直接调用cd2>文件名并将其放入文件名中。如果这不是blat所做的,那么您需要了解它是如何获取数据并以这种形式传递的。

相关问题 更多 >

    热门问题