Message121658
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. |
|
Date |
User |
Action |
Args |
2010-11-20 14:47:07 | jerith | set | recipients:
+ jerith, gvanrossum, gward, terry.reedy, mark.dickinson, tlynn, palfrey, Phillip.M.Feldman@gmail.com, BreamoreBoy |
2010-11-20 14:47:07 | jerith | set | messageid: <1290264427.08.0.0823264783687.issue1859@psf.upfronthosting.co.za> |
2010-11-20 14:47:05 | jerith | link | issue1859 messages |
2010-11-20 14:47:05 | jerith | create | |
|