stdout custom

castironpi at gmail.com castironpi at gmail.com
Sun Mar 16 20:27:28 EDT 2008


The code should have extra colons.

>>> class ThreadedOut:
...     def __init__( self, old ):
...             self._old= old
...     def write( self, s ):
...             self._old.write( ':' )
...             return self._old.write( s )
...     def flush( self ):
...             self._old.flush()
...
>>> import sys
>>> thout= ThreadedOut( sys.stdout )
>>> olds= sys.stdout, sys.stderr, sys.__stderr__, sys.__stdout__
>>> sys.stdout= sys.stderr= sys.__stderr__= sys.__stdout__= thout
>>> 0
:0:
>>>
>>> 123
:123:
>>>
>>>

Specifically, before the prompts.  Where does the prompt write come
from; why doesn't it honor my settings of sys.stdout and sys.stderr?



More information about the Python-list mailing list