How can I create a BufferedReader object from a standard file object like sys.stdin or what do you get from 'open'?
(Reference: I need the peek () method, which standard file objects do not work with. Any suggestions to solve this problem are also welcome.)
I would have expected this to work, but it is not:
>>> import sys >>> import io >>> io.BufferedReader(sys.stdin) Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'file' object has no attribute 'readable'
(This is Python 2.7)
Yes, it turned out, at least for everything that has a file descriptor.
stream = sys.stdin, or open(...), etc. reader = io.open(stream.fileno(), mode='rb', closefd=False)
EvanED May 19 '11 at 21:39 2011-05-19 21:39
source share