私はpython 2.7.3を実行しており、osモジュールに関連するいくつかの基本的なことを行っています。
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')
当然のことながら、オンライン ドキュメントにもまったく同じことが書かれています。何が起きてる?