sys.stdout assign to- bug

castironpi at gmail.com castironpi at gmail.com
Thu Mar 13 03:10:06 EDT 2008


> import sys
> class ThreadedOut:
>         def __init__( self, old ):
>                 self._old= old
>         def write( self, s ):
>                 self._old.write( s )
> sys.stdout= ThreadedOut( sys.stdout )
>
> Python 3.0a2 WinXP, on the console.  'a' is undeclared but error
> message isn't thrown.  With 'sys.stdout= Thr...' commented:

> stdout and stderr needn't be built-in file objects: any object is
> acceptable as long as it has a write() method that takes a string
> argument.

Adding

	def flush( self ):
		self._old.flush()

fixed it.  Can we get that in the docs?



More information about the Python-list mailing list