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
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