Message151945
I'd actually suggest that as the default behaviour (and is a good argument in favour of a dedicated function in textwrap - both suggested alternatives will blithely add whitespace to otherwise empty lines).
To handle the empty line requires either switching to an re.sub() based solution or adding a conditional expression:
'\n'.join(((4 * ' ') + x if x else x) for x in s.splitlines())
I should probably also explicitly address the "why not textwrap.fill()?" alternative: because fill() does a lot more than simple indenting. |
|
Date |
User |
Action |
Args |
2012-01-25 13:59:04 | ncoghlan | set | recipients:
+ ncoghlan, amaury.forgeotdarc |
2012-01-25 13:59:03 | ncoghlan | set | messageid: <1327499943.96.0.468988827529.issue13857@psf.upfronthosting.co.za> |
2012-01-25 13:59:03 | ncoghlan | link | issue13857 messages |
2012-01-25 13:59:02 | ncoghlan | create | |
|