Re: Print a list to a string?

2007-11-01 Thread mrstephengross
> >>> import cStringIO > >>> s = cStringIO.StringIO() > >>> print >>s, [1, 2, 1.0/5, 'hello world'] > >>> s.getvalue() Thanks--this works perfectly! -_Steve -- http://mail.python.org/mailman/listinfo/python-list

Re: Print a list to a string?

2007-10-31 Thread Steven D'Aprano
On Wed, 31 Oct 2007 22:17:48 +, mrstephengross wrote: > I would like to get the results of a print operation placed in a string. s = str(x) If you specifically need to capture the output of print, then something like this: >>> import cStringIO >>> s = cStringIO.StringIO() >>> print >>s,

Re: Print a list to a string?

2007-10-31 Thread Bruno Desthuilliers
mrstephengross a écrit : > I would like to get the results of a print operation print is a statement, it doesn't yield any 'result'. > placed in a > string. For instance, you can very easily create a list and print it > to stdout: > > x = [1,2,3] > print x # Will print [1,2,3] > > What if

Re: Print a list to a string?

2007-10-31 Thread Gary Herron
mrstephengross wrote: > I would like to get the results of a print operation placed in a > string. For instance, you can very easily create a list and print it > to stdout: > > x = [1,2,3] > print x # Will print [1,2,3] > > What if I want the text "[1,2,3]" placed in a string? For instance, > s

Print a list to a string?

2007-10-31 Thread mrstephengross
I would like to get the results of a print operation placed in a string. For instance, you can very easily create a list and print it to stdout: x = [1,2,3] print x # Will print [1,2,3] What if I want the text "[1,2,3]" placed in a string? For instance, something like: x = [1,2,3] str =