Use 0 for the optional 3rd arg to open() (and most other things that
return a standard file object). For stdout/stderr, use "python -u".
It is done this way because stdio crashes spectacularly (on some
systems) if you call set*buf() after doing any I/O, and there's no
portable way to test whether it is still allowed to call it, so I would
have to maintain my own state variable just to implement a safe
setbuf() method... Adding it to open made a lot more sense.
--Guido van Rossum (home page: http://www.python.org/~guido/)
On Mon, 5 Aug 1996, Aaron Watters wrote:
> Quicky: how do you do unbuffered stdout?
> I don't see any setbuf anywhere and I don't wanna
> hafta flush() everywhere. fcntl? (unix/solaris)
> thanks,
> aaron watters.
>
Not sure the right way to do this, but open() and fdopen() both
take a third argument that is the buffersize.
Dave
you can use the -u switch or setenv PYTHONUNBUFFERED 1, or even modify
main.c, or sysinit() in sysmodule.c so that it creates unbuffered sys.stdout
and sys.stderr, or add setbuf and setvbuf methods to the Python file type.
My guess is you'll prefer the 2 first ways :-)
Benoit
>
> Quicky: how do you do unbuffered stdout?
> I don't see any setbuf anywhere and I don't wanna
> hafta flush() everywhere. fcntl? (unix/solaris)
> thanks,
> aaron watters.
How about
python -u