This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author maubp
Recipients maubp
Date 2016-11-10.16:35:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1478795701.76.0.659915154246.issue28660@psf.upfronthosting.co.za>
In-reply-to
Content
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)
History
Date User Action Args
2016-11-10 16:35:01maubpsetrecipients: + maubp
2016-11-10 16:35:01maubpsetmessageid: <1478795701.76.0.659915154246.issue28660@psf.upfronthosting.co.za>
2016-11-10 16:35:01maubplinkissue28660 messages
2016-11-10 16:35:01maubpcreate