2008-08-27
Unbuffered IO in Python
I was looking around for a while on how to get unbuffered IO in Python, and eventually discovered the following entry in the man page:
Pretty cool, except in Perl you can turn on and off unbuffered IO as you need. With Python it's wither on or off globally, but then you can use different methods for reading and writing buffered vs unbuffered IO.
Also check out this article explaining some other useful IO stuff...
-u Force stdin, stdout and stderr to be totally unbuffered. On systems
where it matters, also put stdin, stdout and stderr in binary mode. Note
that there is internal buffering in xreadlines(), readlines() and
file-object iterators ("for line in sys.stdin") which is not
influenced by this option. To work around this, you will want to use
"sys.stdin.readline()" inside a "while 1:" loop.
Pretty cool, except in Perl you can turn on and off unbuffered IO as you need. With Python it's wither on or off globally, but then you can use different methods for reading and writing buffered vs unbuffered IO.
Also check out this article explaining some other useful IO stuff...
Labels: python