"print" strange with Sybase module
Chris
chris at 2s2iNO_SPAM.com
Sun Jan 28 09:21:26 EST 2001
Erwin & Fredrik -
Thank you both very much. Your responses have shed significant light into
dark areas for me!
Chris
Fredrik Lundh <fredrik at effbot.org> wrote in message
news:_LVc6.9609$Qb7.1426225 at newsb.telia.net...
> Erwin S. Andreasen wrote:
> > AFAICS, there is no way to turn the buffering to be line-based on an
existing
> > file object (it might be an idea for a future release?). You could do
> > something like:
> >
> > sys.stdout = os.fdopen(os.dup(sys.stdout.fileno()), 'w', 1)
> >
> > which would reopen standard output as a line-buffered (the 1) stream,
> > i.e. every time you have written a full line to the file object, it's
flushed
> > -- just like when you run the program on the console.
>
> here's a variant, which works for any kind of sys.stdout:
>
> class UnbufferedStream:
> def __init__(self, stream):
> self.stream = stream
> def write(self, data):
> self.stream.write(data)
> self.stream.flush()
> def __getattr__(self, attr):
> # delegate everything else
> return getattr(self.stream, attr)
>
> sys.stdout = UnbufferedStream(sys.stdout)
>
> Cheers /F
>
> <!-- (the eff-bot guide to) the standard python library:
> http://www.pythonware.com/people/fredrik/librarybook.htm
> -->
>
>
>
More information about the Python-list
mailing list