In article <[EMAIL PROTECTED]>,
 JanC <[EMAIL PROTECTED]> wrote:

> Something like this:
> 
> py> import cStringIO
> py> import sys
> py>
> py> def foo():
> ...     print "test"
> ...
> py> f = cStringIO.StringIO()
> py> sys.stdout = f
> py> foo()
> py> s = f.getvalue()
> py> sys.stdout = sys.__stdout__

You should always save stdout instead of using __stdout__. It may not be 
the same! I don't think anyone should *ever* use __stdout__ except when 
debugging. See also:

  http://mail.python.org/pipermail/python-dev/2000-October/010144.html

> py> f.close()
> py> print s.capitalize()
> Test

Just
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to