redirect sys.stdout to C++ ?

Donn Cave donn at drizzle.com
Sat Dec 21 11:34:18 EST 2002


Quoth Tatsujin <tatsujin at despammed.com>:
..
| I guess what I basically want to do is subclass a file() object class with my own 
| type, and assign an instance of that to sys.stdout and sys.stderr. I've read the 
| documentation about how to create new types with C/C++, but i couldn't easily deduce 
| how to go about a subclassing of an existing (builtin) type. Is this the way to go? 
| Or is there an easier way? Any pointers to stuff out there that do similar stuff? I'm 
| not using any helper packages (like boost or swig), just plain Python API.

That isn't precisely the way to go.  The key point here is that unlike C++,
Python doesn't care if stdout is subclass of the builtin file object type -
doesn't make any difference at all.  So maybe it is indeed easier - you
only need an object that supports the functions that stdout going to use.

If you have the Python source, cStringIO does that (much more than you
need, though.)

	Donn Cave, donn at drizzle.com



More information about the Python-list mailing list