8

I am writing in python 3.5.1 and I am a programming novice.

I use gedit with a pep8 and pyflakes plugins showing style mistakes according to the python style guide. I do not know whether to follow the style recommendation to the letter or not.

I have, however, three recurring style flaws indicated by E501: line too long (80 > 79 characters), E502: the backslash is redundant between brackets and E128/E127/...: continuation line under-indented for visual indent. Screenshots below.

My two questions are:

  1. How can I adequately make a line break in python in order to avoid E501 and the subsequent style errors E502 and E127/128?
  2. Is it helpful to follow the style guide pep8 to the letter, especially with publication in mind? What do advanced python programmers say?

E501: enter image description here

E502: enter image description here

E127/128...: enter image description here

Jamie Bull
  • 12,889
  • 15
  • 77
  • 116
Til Hund
  • 1,543
  • 5
  • 21
  • 37
  • 3
    "With publication in mind", yes, absolutely, follow the style guide. No exceptions; standards exist for mutual comprehensibility. If you don't like the style guide, submit a new PEP; in this case, expect it to be rejected. – msw Jan 19 '16 at 11:11
  • Why has this been closed? There's a perfectly good answer to written about point 2, how to do line breaks that will be acceptable to PEP8. Edit - as @msw has now provided. – Jamie Bull Jan 19 '16 at 11:22
  • My 2c worth: 1. Definitely don't use backslash continuation when you don't need it, eg inside brackets. 2. Your indentation on those continued lines is way too big. 3. Plenty of people treat the line length thing as a suggestion rather than as a rigid restriction, since modern monitors are a lot bigger than they used to be. OTOH, sticking to the standard will make your code look better in many places, including here on SO. – PM 2Ring Jan 19 '16 at 11:24
  • 2
    @msw: I suspect that `_()` is an i18n function. See http://stackoverflow.com/a/2964256/4014959 – PM 2Ring Jan 19 '16 at 11:29

1 Answers1

12

"How can I adequately make a line break in python in order to avoid E501 and the subsequent style errors E502 and E127/128?"

progress = Utils.ProgressMeter('Source strings separated by white '
    'space are automatically concatenated by the '
    'interpreter and parenthesis are the natural syntax '
    'for line continuation. Remember to use trailing '
    'spaces.')

Since error E502 is already inside parentheses, the backslash is redundant. Did you try eliminating it?

msw
  • 42,753
  • 9
  • 87
  • 112