[stdlib-sig] textwrap module and hyphenation

Sylvain Fourmanoit syfou at users.sourceforge.net
Sat Apr 19 08:18:30 CEST 2008

I just noticed the textwrap module in the standard library will break and 
line-wrap hyphenated words given the opportunity:

>>> from textwrap import wrap
>>> wrap('yaba daba-doo', width=10)
['yaba daba-', 'doo']

I have two questions about that:

1) Wouldn't it be worth mentioning this in the Python Library Reference
    (or it is just too obvious)?

2) Wouldn't it be useful to have a simple way to turn it off? Something

>>> from textwrap import wrap
>>> wrap('yaba daba-doo', width=10, break_hyphenated_words=False)
['yaba', 'daba-doo']

Since proper line-wrapping of hyphenated words is language-dependent and 
can interact with other orthographic and typesetting practices, I think it 
would be nicer to have a documented way to turn it off completely.

Granted, it's not hard to manually do either; on Python 2.5.2 (as well as 
on Python 2.6 r62386), it's just a matter of setting the 
"TextWrapper.wordsep_re" attribute to "re.compile('(\s+)')"...  I 
think having a publicly documented attribute wouldn't hurt anyway.

Sylvain <syfou at users.sourceforge.net>

The IBM 2250 is impressive ...
if you compare it with a system selling for a tenth its price.
 		-- D. Cohen

More information about the stdlib-sig mailing list