To re or not to re ... ( word wrap function?)

Magnus Lie Hetland mlh at idi.ntnu.no
Mon Sep 24 15:24:15 EDT 2001


"Chris Barker" <chrishbarker at home.net> wrote in message
news:mailman.1001355746.18274.python-list at python.org...
> Thanks to all of you who posted code: I've learned something from each
> one.
>
>
> I did notice that no one used an re-based solution, except Skip using
>
> re.split(r'\s+', s)
>
> Is this any different than string.split(s) ?

Not that I can see.

> Note that I didn't want to use either of these, as they would kill any
> sequences of whitespace, such as two spaces after a sentence.

Well -- you're not supposed to have that, are you? <wink>

(A bit larger than a single space when typeset, sure -- but two
spaces in text? Yuck...)

So, you basically want to keep your whitespace? Then wrappint will
be hard... What whitespace will you allow to be changed into
a newline, for instance?

> tex_wrap looks very nice but is really overkill for this application.
>
>
> I also noticed that no one took my approach, which was to start at the
> end of the line and work backwards looking for space. You all took the
> approach of building the new line word by word from the beginning.

I'm sure that's a nice approach -- but how do you avoid ending up with
a short first line? (A short last line is OK.)

> hmmmm.
>
> -Chris

--

  Magnus Lie Hetland         http://www.hetland.org

 "Reality is that which, when you stop believing in
  it, doesn't go away."           -- Philip K. Dick






More information about the Python-list mailing list