tags:

views:

767

answers:

4

In other words, what's the sprintf equivalent to pprint?

+12  A: 

pprint.pformat

SilentGhost
+3  A: 

Are you looking for pprint.pformat?

sykora
+2  A: 

Assuming you really do mean pprint from the pretty-print library, then you want the pprint.pformat method.

If you just mean print, then you want str()

Andrew Jaffe
+1  A: 

Something like this:

import pprint, StringIO

s = StringIO.StringIO()
pprint.pprint(some_object, s)
print s.getvalue() # displays the string
Hans Nowak