Jeremy Thurgood <fir...@gmail.com> added the comment:

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.

----------
nosy: +jerith

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue1859>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to