New submission from Peter:

Quoting https://docs.python.org/2/library/textwrap.html

width (default: 70) The maximum length of wrapped lines. As long as there are 
no individual words in the input text longer than width, TextWrapper guarantees 
that no output line will be longer than width characters.

It appears that with break_long_words=True and break_on_hyphens=True, any 
hyphenated term longer than the specified width does not get preferentially 
broken at a hyphen.

Example input:

We used the enyzme 2-succinyl-6-hydroxy-2,4-cyclohexadiene-1-carboxylate 
synthase.


Using break_long_words=True, break_on_hyphens=True
==================================================
We used the enyzme 2-succinyl-6-hydroxy-2,4-cycloh
exadiene-1-carboxylate synthase.
==================================================


Expected result using break_long_words=True, break_on_hyphens=True
==================================================
We used the enyzme 2-succinyl-6-hydroxy-2,4-
cyclohexadiene-1-carboxylate synthase.
==================================================


Given a width=50, then the 53 character long "word" of 
"2-succinyl-6-hydroxy-2,4-cyclohexadiene-1-carboxylate" must be split 
somewhere, and since break_on_hyphens=True it should break at a hyphen as shown 
above as the desired output.


Sample code:


import textwrap
w = 50
text = "We used the enyzme 
2-succinyl-6-hydroxy-2,4-cyclohexadiene-1-carboxylate synthase."
print("Input:")
print("=" * w)
print(text)
print("=" * w)
print("Using break_long_words=True, break_on_hyphens=True")
print("=" * w)
print(textwrap.fill(text, width=w, break_long_words=True, 
break_on_hyphens=True))
print("=" * w)

----------
messages: 280522
nosy: maubp
priority: normal
severity: normal
status: open
title: TextWrapper break_long_words=True, break_on_hyphens=True on long words
versions: Python 2.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28660>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to