So there are two problems. I have this chunk of code in Sublime Text 3, where I use Anaconda package (relevant whitespace will be shown as •
, as it is displayed in ST3; Python.sublime-settings are shown at the end of this post):
elif choice == "taunt bear" and not bear_moved:
••••••••print("The•bear•has•moved•from•the•door.•You•can•go•through•it•now"
)
bear_moved = True
First problem:
I have Word Wrap enabled and the ruler set at 80, so it wraps the code automatically, having exactly 79 characters on the line with "print..." and 1 character on the next line. But linter gives me an error "[W] PEP8 (E501): line too long (80 > 79 characters)". I have right parentheses auto-indented on the next line, so there is no violation of the "79 characters per line" rule. What could be the problem here? Is it that the line should always be less than 80 chars, even if it is spanning multiple lines?
Second problem:
elif choice == "taunt bear" and not bear_moved:
••••••••print("""The•bear•has•moved•from•the•door.
•••••••••••••••••You•can•go•through•it•now""")
bear_moved = True
Here I wanted to get rid of the ">79 characters" error and make a multi-line string. The thing is, when I split two sentences in the string over two lines to be able to align them according to PEP8 rules, I have to indent them, and indentation means excessive whitespace inside the string, which is not what I want. Here's how it should work ideally, with a needed space character right after the end of the first sentence, and no whitespace used to indent the second half of the string:
elif choice == "taunt bear" and not bear_moved:
••••••••print("""The•bear•has•moved•from•the•door.•
You•can•go•through•it•now""")
bear_moved = True
Python.sublime-settings:
{
// editor options
"draw_white_space": "all",
// tabs and whitespace
"auto_indent": true,
"rulers": [80],
"smart_indent": true,
"tab_size": 4,
"trim_automatic_white_space": true,
"use_tab_stops": false,
"word_wrap": true,
"wrap_width": 80
}
You can make use of Python string concat mechanisms and write the string in single quotes as seen in the example:
elif choice == "taunt bear" and not bear_moved:
••••••••print("The•bear•has•moved•from•the•door.•"
"You•can•go•through•it•now")
bear_moved = True
So your code is PEP8 compliant and the string is in the desired format.