Saturday 31 August 2013

Python os.popen requires an integer?

Python os.popen requires an integer?

I'm running python 2.7.3 and doing some basic stuff involving the os module.
import os
def main():
f= os.popen('cat > out', 'w',1)
os.write(f, 'hello pipe')
os.close(f)
main()
Based on examples I've seen I would expect the code to work, but the
interpreter gives this error:
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
Okay, off to the documentation. The help page says:
write(...)
write(fd, string) -> byteswritten
Write a string to a file descriptor.
fd seems to stand for file descriptor. Presumably this is what you get
when you do something like:
file = open('test.py')
No surprise, online documentation says the exact same thing. What's going
on here?

No comments:

Post a Comment