When creating a pipe with os.pipe()
it returns 2 file numbers; a read end and a write end which can be written to and read form with os.write()
/os.read()
; there is no os.readline(). Is it possible to use readline?
import os
readEnd, writeEnd = os.pipe()
# something somewhere writes to the pipe
firstLine = readEnd.readline() #doesn't work; os.pipe returns just fd numbers
In short, is it possible to use readline when all you have is the file handle number?
You can use os.fdopen()
to get a file-like object from a file descriptor.
import os
readEnd, writeEnd = os.pipe()
readFile = os.fdopen(readEnd)
firstLine = readFile.readline()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With