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 <[email protected]>
<http://bugs.python.org/issue15510>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com