My code:
if 'certainField' in myData['meta']['loc']:
something = myData['meta'] \ <- PEP8 E11 raised for this
['loc'] \ <- PEP8 E11 raised for this
['certainField'] \ <- PEP8 E11 raised for this
['thefield']
The code works as expected. But PEP 8 E211 is raised for the second, third and fourth line claiming whitespace before '['
I don't get it. How can I format this so that PEP 8 is satisfied?
You can wrap your statement into parenthesis and remove \
if 'certainField' in myData['meta']['loc']:
something = (myData['meta']
['loc']
['certainField']
['thefield'])
The preferred way of wrapping long lines is by using Python's implied line continuation inside parentheses, brackets and braces. Long lines can be broken over multiple lines by wrapping expressions in parentheses. These should be used in preference to using a backslash for line continuation.
Backslashes may still be appropriate at times. For example, long, multiple with -statements cannot use implicit continuation, so backslashes are acceptable:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With