numpy数组tofile到stdout和fromfile从stdin

时间:2019-05-23 07:18:49

标签: python-3.x numpy pipe

我希望从stdin中读取python代码并将其写入stdout。

这是我正在尝试的代码

#!/usr/bin/python
# filename: pass.py
import sys
import numpy as N
a = N.frombuffer(sys.stdin.buffer.read(), dtype = 'b', count = -1)
a.tofile(sys.stdout.buffer)

此代码以某种方式工作:

$ seq 10 | python3 pass.py > out

但这不起作用:

$ seq 10 | python3 pass.py 
Traceback (most recent call last):
  File "pass.py", line 6, in <module>
    a.tofile(sys.stdout.buffer)
OSError: obtaining file position failed

如何使此代码起作用?

0 个答案:

没有答案