When using Python's textwrap library, how can I turn this:
short line,
long line xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
into this:
short line,
long line xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxx
I tried:
w = textwrap.TextWrapper(width=90,break_long_words=False)
body = '\n'.join(w.wrap(body))
But I get:
short line, long line xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
(spacing not exact in my examples)
try
that seemed to fix the problem for me
I worked that out from what I read here (I've never used textwrap before)
Here is a little module that can wrap text, break lines, handle extra indents (eg.a bulleted list), and replace characters/words with markdown!
Will output:
Fish Island is a low center polygonal peatland on the transition between the Mackenzie River Delta and the Tuktoyaktuk Coastal Plain.
It is underlain by continuous permafrost, peat deposits exceede the annual thaw depth.
$Sphagnum$ dominates the polygon centers with a caonpy of $Equisetum$ and sparse $Carex$. Dwarf $Salix$ grows allong the polygon rims. $Eriophorum$ and carex fill collapsed ice wedges.
Characters between the $$ would be in italics if you were working in matplotlib for instance, but the $$ won't count towards the line spacing since they are added after!
So if you did:
You'd get:
It looks like it doesn't support that. This code will extend it to do what I need though:
http://code.activestate.com/recipes/358228/
I had to a similar problem formatting dynamically generated docstrings. I wanted to preserve the newlines put in place by hand and split any lines over a certain length. Reworking the answer by @far a bit, this solution worked for me. I only include it here for posterity: