我正在尝试使用Python 3.4中的subprocess.Popen打开的管道中编写一个numpy数组数据。这里是Python - 将numpy数组数据写入用Popen打开的管道
import numpy
import subprocess
myArray = numpy.arange(10000).reshape([100,100])
fullCmd = "xpaset DS9Test array [xdim=100,bitpix=64,arch=littleendian,ydim=100]"
mp = subprocess.Popen(
fullCmd,
shell = True,
stdin = subprocess.PIPE,
stdout = subprocess.PIPE,
stderr = subprocess.STDOUT,
bufsize = 0
)
myArray.tofile(mp.stdin)
不幸的是,我收到以下错误代码:
File "/Users/avigan/Work/HC-HR/FTS/test.py", line 25, in <module>
myArray.tofile(mp.stdin)
OSError: first argument must be a string or open file
但是,如果我这样做:
print(mp.stdin)
<_io.FileIO name=71 mode='wb'>
我解释这是一个迹象,表明文件描述符确实开放。
有人看到这里有什么不对吗?
你必须看看编译的'numpy'代码,看看'tofile'如何测试这个参数。该测试可能不像文档所示的一般。 – hpaulj