Message280522
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) |
|
Date |
User |
Action |
Args |
2016-11-10 16:35:01 | maubp | set | recipients:
+ maubp |
2016-11-10 16:35:01 | maubp | set | messageid: <1478795701.76.0.659915154246.issue28660@psf.upfronthosting.co.za> |
2016-11-10 16:35:01 | maubp | link | issue28660 messages |
2016-11-10 16:35:01 | maubp | create | |
|