Need your help

Ervin Hegedüs airween at gmail.com
Thu Apr 28 13:32:00 CEST 2011


hello,

On Thu, Apr 28, 2011 at 01:20:16PM +0200, Ervin Hegedüs wrote:
> #!/usr/bin/python
> 
> import a
> import b
> 
> import sys
> import StringIO
> 
> output = StringIO.StringIO()
> 
> def c():
>     # save default stdout
>     tout = sys.stdout
>     # redirect stdout to StringIO object
>     sys.stdout = output
>     # a.a() prints their output to StringIO object
>     a.a()
>     # back up default stdout
>     sys.stdout = tout
>     # print StringIO object value
>     print "retval:", output.getvalue()
> 
> c()

sorry,

this is a littlebit more abstact example, it gives a StringIO
object, instead of write to a file - of course, you can do what
you want with that string...


a.
 



More information about the Python-list mailing list