Python: Too long raw string, multiple lines

You can use parenthesis to trigger automatic line continuation. The strings will be automatically concatenated.

pathProject = (
    r"C:\Users\Account\OneDrive"
    r"\Documents\Projects\2016\Shared"
    r"\Project-1\Administrative\Phase-1\Final"
)

You almost got it! The issue is that raw strings cannot end with a backslash. Hence, this works:

pathProject = r'''C:\Users\Account\OneDrive
\Documents\Projects\2016\Shared
\Project-1\Administrative\Phase-1
\Final'''

Note that if you put spaces into the triple-quoted string to indent it, like in your example, there will be spaces in your string, which you don't want. If you like indents, you can use automatic line continuation with parentheses as suggested in Brendan's answer. Again, make sure that the lines don't end with a backslash.

Tags:

Python