What is the proper indentation for Python multiline strings within a function?
def method():
string = """line one
line two
line three"""
or
def method():
string = """line one
line two
line three"""
or something else?
It looks kind of weird to have the string hanging outside the function in the first example.
You probably want to line up with the
"""Since the newlines and spaces are included in the string itself, you will have to postprocess it. If you don’t want to do that and you have a whole lot of text, you might want to store it separately in a text file. If a text file does not work well for your application and you don’t want to postprocess, I’d probably go with
If you want to postprocess a multiline string to trim out the parts you don’t need, you should consider the
textwrapmodule or the technique for postprocessing docstrings presented in PEP 257: