G+: Useful Python function of the day: textwrap.dedentGreat if …

David Coles
Useful Python function of the day: textwrap.dedent

Great if you want to inline a large block of text:

def test():
# end first line with \ to avoid the empty line!
s = '''\
hello
world
'''
print(repr(s)) # prints ' hello\n world\n '
print(repr(dedent(s))) # prints 'hello\n world\n'


Often this is nicer than joining multiple strings using parens:

s = ("This is a long line"
" that hath been split in twain")
print(repr(s)) # prints 'This is a long line that hath been split in twain'


#python

6.4. textwrap — Text wrapping and filling — Python 3.6.2 documentation


(+1's) 3