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

Chris Barker chrishbarker at
Mon Sep 24 20:44:25 CEST 2001

Thanks to all of you who posted code: I've learned something from each

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) ?

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.

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.



Christopher Barker,
ChrisHBarker at                 ---           ---           --- ---@@       -----@@       -----@@
                                   ------@@@     ------@@@     ------@@@
Oil Spill Modeling                ------   @    ------   @   ------   @
Water Resources Engineering       -------      ---------     --------    
Coastal and Fluvial Hydrodynamics --------------------------------------

More information about the Python-list mailing list