我正在運行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