[issue15510] textwrap.wrap('') returns empty list
R. David Murray
report at bugs.python.org
Wed Aug 8 22:34:55 CEST 2012
R. David Murray added the comment:
Also you will note that the return of the empty list for an empty line is exactly what you want for wrapping multiple line-break-delimited paragraphs. Consider:
>>> doc = "a para\nanother para\n\na third, but with an extra blank line between\n"
>>> for line in doc.splitlines():
... print('\n'.join(textwrap.wrap(line, width=5)))
... if line:
... print()
a
para
anoth
er
para
a thi
rd,
but
with
an
extra
blank
line
betwe
en
In other words, we need to add a blank line after our formatted paragraph, unless it is empty, in which case we don't want to add one or we'll have an extra. This assumes that single-line-paragraphs do not have blank lines between them...if they do, then the algorithm is even simpler, as you don't need the if.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15510>
_______________________________________
More information about the Python-bugs-list
mailing list