我希望从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
如何使此代码起作用?