Wrapping text?

Graham Ashton graham at coms.com
Sun Jun 24 13:06:04 EDT 2001


I've got XML files that define the contents of emails, that look a bit
like this:

  <subject>
    Blah blah blah
  </subject>
  <body>
    Lots more of the same, ...

      This bit is indented.

    ... blah blah blah.
  </body>

When I parse it with xml.sax I get the same indentation, so that my body
variable starts with a new line and then 4 spaces. What I'd like is to be
able to chop the white space off the front of each line, but not so much
that the indented line in the middle of the body doesn't lose it's
indentation.

The only idea I've had so far is to write my startElement() method so that
it keeps track of indentation and doesn't store the leading whitespace
where I don't want it to. I'm sure I could do that bit (though I'm hoping
that there's a much easier way), but what about wrapping the resulting
text so that it's 76 cols wide? (I've no control over the width of the
paragraphs that are entered by users).

Thanks.

--
Graham



More information about the Python-list mailing list