我正在运行python 2.7.3并执行一些涉及os模块的基本工作。基于我见过我希望工作代码示例Python os.popen需要一个整数?
import os
def main():
f= os.popen('cat > out', 'w',1)
os.write(f, 'hello pipe')
os.close(f)
main()
,但解释给出了这样的错误:
Traceback (most recent call last):
File "./test.py", line 11, in <module>
main()
File "./test.py", line 8, in main
os.write(f, 'hello pipe')
TypeError: an integer is required
好了,关闭的文档。帮助页面上说:
write(...)
write(fd, string) -> byteswritten
Write a string to a file descriptor.
fd似乎代表文件描述符。想必这是你做什么时,你会得到:
file = open('test.py')
毫不奇怪,在线文档说,完全一样的东西。 这是怎么回事?
使用'subprocess'? –
因为我想从网站获取数据,并且随着数据传入另一个进程。有没有更好的方法来做到这一点与子进程? – Muricula