【发布时间】:2016-06-14 16:46:02
【问题描述】:
我想将grep 的输出缓冲到缓冲区,然后用pandas 读取它以避免将巨大的原始文件加载到内存中:
import subprocess
import io
import pandas as pd
firstfile = "~/references/rs_hg19.snps.uniq.bed"
outf = io.StringIO("")
p0 = subprocess.Popen(('grep', '-P', "chr22\\t", firstfile), stdout=subprocess.PIPE)
p1 = subprocess.call(["head", "-n5", ], stdin=p0.stdout, stdout= outf)
p0.wait()
print(pd.read_table(outf)
)
我收到一个错误:
Traceback (most recent call last)
File "test.py", line 9, in <module>
p1 = subprocess.call(["head", "-n1", ], stdin=p0.stdout, stdout= outf)
File "/opt/rh/python33/root/usr/lib64/python3.3/subprocess.py", line 520, in call
with Popen(*popenargs, **kwargs) as p:
File "/opt/rh/python33/root/usr/lib64/python3.3/subprocess.py", line 786, in __init__
errread, errwrite) = self._get_handles(stdin, stdout, stderr)
File "/opt/rh/python33/root/usr/lib64/python3.3/subprocess.py", line 1294, in _get_handles
c2pwrite = stdout.fileno()
io.UnsupportedOperation: fileno
即使我直接运行它,not from any IDE。
有什么想法/建议吗?
系统一:CentOS6.7、Python3.3
系统2:MacOSX10.10.5、Python3.5
【问题讨论】:
-
"-n1"后面应该有逗号吗? -
语法上没关系
标签: python io subprocess