Re: Collect output to string

2010-11-24 Thread Hrvoje Niksic
Burton Samograd writes: > Terry Reedy writes: > >> On 11/23/2010 3:02 PM, Chris Rebert wrote: >> If you are using print or print(), you can redirect output to the >> StringIO object with >>sfile or file=sfile. I use the latter in a >> custom test function where I normally want output to the scre

Re: Collect output to string

2010-11-24 Thread Burton Samograd
Terry Reedy writes: > On 11/23/2010 3:02 PM, Chris Rebert wrote: > If you are using print or print(), you can redirect output to the > StringIO object with >>sfile or file=sfile. I use the latter in a > custom test function where I normally want output to the screen but > occasionally want to cap

Re: Collect output to string

2010-11-23 Thread Terry Reedy
On 11/23/2010 3:02 PM, Chris Rebert wrote: On Tue, Nov 23, 2010 at 11:53 AM, Burton Samograd wrote: Hello, I was wondering if there is any way in python to 'collect output to string' as in some lisps/schemes. Output being, printed output to the console using print. Rebind sys.s

Re: Collect output to string

2010-11-23 Thread Chris Rebert
On Tue, Nov 23, 2010 at 1:15 PM, Ian wrote: > On Nov 23, 1:59 pm, Burton Samograd wrote: >> Thanks for the tip.  Here's my function: >> >> def with_output_to_string(f, args): >>      oldstdout = sys.stdout >>      buffer = StringIO.StringIO() >>      sys.stdout = buffer >>      apply(f, args) >>

Re: Collect output to string

2010-11-23 Thread Ian
On Nov 23, 1:59 pm, Burton Samograd wrote: > Thanks for the tip.  Here's my function: > > def with_output_to_string(f, args): >      oldstdout = sys.stdout >      buffer = StringIO.StringIO() >      sys.stdout = buffer >      apply(f, args) >      sys.stdout = oldstdout >      return buffer.getval

Re: Collect output to string

2010-11-23 Thread MRAB
On 23/11/2010 20:59, Burton Samograd wrote: Chris Rebert writes: On Tue, Nov 23, 2010 at 11:53 AM, Burton Samograd wrote: Hello, I was wondering if there is any way in python to 'collect output to string' as in some lisps/schemes. Output being, printed output to the console u

Re: Collect output to string

2010-11-23 Thread Burton Samograd
Chris Rebert writes: > On Tue, Nov 23, 2010 at 11:53 AM, Burton Samograd wrote: >> Hello, >> >> I was wondering if there is any way in python to 'collect output to >> string' as in some lisps/schemes.  Output being, printed output to the >> cons

Re: Collect output to string

2010-11-23 Thread Chris Rebert
On Tue, Nov 23, 2010 at 11:53 AM, Burton Samograd wrote: > Hello, > > I was wondering if there is any way in python to 'collect output to > string' as in some lisps/schemes.  Output being, printed output to the > console using print. Rebind sys.stdout to a StringIO objec

Collect output to string

2010-11-23 Thread Burton Samograd
Hello, I was wondering if there is any way in python to 'collect output to string' as in some lisps/schemes. Output being, printed output to the console using print. Thanks. -- Burton Samograd -- http://mail.python.org/mailman/listinfo/python-list