[issue13857] Add textwrap.indent() as counterpart to textwrap.dedent()
Nick Coghlan
report at bugs.python.org
Wed Jan 25 14:59:03 CET 2012
Nick Coghlan <ncoghlan at gmail.com> added the comment:
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.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13857>
_______________________________________
More information about the Python-bugs-list
mailing list