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 jerith
Recipients BreamoreBoy,, gvanrossum, gward, jerith, mark.dickinson, palfrey, terry.reedy, tlynn
Date 2010-11-20.14:47:05
SpamBayes Score 7.18569e-08
Marked as misclassified No
Message-id <>
The weird behaviour is caused by newlines being treated as normal whitespace characters and not actually causing _wrap_chunks() to break the line. This means that it builds "lines" of up to 'width' characters which may contain newlines:

>>> text = '''\
... aaa aaa aaa
... bbb bbb bbb
... ccc ccc ccc
... ddd ddd ddd'''
>>> T = TextWrapper(replace_whitespace=False, width=17)    
>>> T.wrap(text)
['aaa aaa aaa\nbbb', 'bbb bbb\nccc ccc', 'ccc\nddd ddd ddd']
>>> for line in T.wrap(text): print(line)
aaa aaa aaa
bbb bbb
ccc ccc
ddd ddd ddd

There's no clean way to deal with this inside _wrap_chunks() (as Greg implied), so I think we should just document the existing behaviour and recommend the splitlines() workaround.

It might be useful to add a wrap_paragraphs() convenience function that does the split/wrap/join, but I don't think that would add enough value to be worth the change.
Date User Action Args
2010-11-20 14:47:07jerithsetrecipients: + jerith, gvanrossum, gward, terry.reedy, mark.dickinson, tlynn, palfrey,, BreamoreBoy
2010-11-20 14:47:07jerithsetmessageid: <>
2010-11-20 14:47:05jerithlinkissue1859 messages
2010-11-20 14:47:05jerithcreate