TextWrapper keepking line breaks?
arnodel at googlemail.com
Tue Mar 11 02:27:36 CET 2008
On Mar 10, 11:31 pm, js <ebgs... at gmail.com> wrote:
> Hi list,
> Can I make TextWrapper keep line breaks in the text?
> For example,
> >>> s = "spam\nham"
> >>> print wrap(s)
> As far as I can tell, there seems no way to do this,
> but before writing my own solution, I want to know whether
> the solution already exists or not.
Don't know but you could write:
>>> import textwrap
>>> def wraplines(text):
... return '\n'.join(textwrap.fill(line) for line in
>>> s = "spam\nham"
>>> print wraplines(s)
More information about the Python-list