sys.stdout assign to- bug

castironpi at gmail.com castironpi at gmail.com
Wed Mar 12 06:55:08 EDT 2008


I'm actually intimidated enough by a few tries I make to say something
on Python-Ideas, that I thought I'd run this by youguys first.

import sys
class ThreadedOut:
	def __init__( self, old ):
		self._old= old
	def write( self, s ):
		self._old.write( s )
sys.stdout= ThreadedOut( sys.stdout )

>>> a
>>> 0
0

Python 3.0a2 WinXP, on the console.  'a' is undeclared but error
message isn't thrown.  With 'sys.stdout= Thr...' commented:

>>> a
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'a' is not defined
>>> 0
0

But the docs say:

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.

What's the catch?



More information about the Python-list mailing list