Author jerith
Recipients BreamoreBoy, Phillip.M.Feldman@gmail.com, 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 <1290264427.08.0.0823264783687.issue1859@psf.upfronthosting.co.za>
In-reply-to
Content
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 bbb
ccc 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.
History
Date User Action Args
2010-11-20 14:47:07jerithsetrecipients: + jerith, gvanrossum, gward, terry.reedy, mark.dickinson, tlynn, palfrey, Phillip.M.Feldman@gmail.com, BreamoreBoy
2010-11-20 14:47:07jerithsetmessageid: <1290264427.08.0.0823264783687.issue1859@psf.upfronthosting.co.za>
2010-11-20 14:47:05jerithlinkissue1859 messages
2010-11-20 14:47:05jerithcreate