PrettyPrint not outputing anything !!

James J. Besemer jb at cascade-sys.com
Thu Aug 15 07:33:11 EDT 2002


> Sunit Joshi wrote:
>
> > str = StringIO.StringIO()
> > PrettyPrint(sXml,str)
> > str.getvalue()
> > prints ''
> >
> > Any ideas what might be wrong.

Fredrik Lundh wrote:

> I'm pretty sure PrettyPrint wants a parsed document, not a string.

No.  The capability when properly accepts arbitrary Python data.

Usage is a little non-intuitive.  I bet Sunit's error is in calling the
function factory rather than the generated pretty printer.

Proper usage:

    import pprint

    pp = pprint.PrettyPrinter(indent=4)  # create a printer function
    pp.pprint( sXml )                # use the created function on data

That should "pretty print" your string.

However, since it's just a string, I'm not sure it'll be much prettier
than with just print.

You also don't say what you really expect.

I'm guessing but the following might help:

    pp.pprint( sXml.split())

Or probably you want to pretty print your XML.
I have no idea how to do that.

REgards

--jb


--
James J. Besemer  503-280-0838 voice
http://cascade-sys.com  503-280-0375 fax
mailto:jb at cascade-sys.com






More information about the Python-list mailing list