pep8 Re: Posting warning message

Cameron Simpson cs at cskk.id.au
Tue Jun 12 20:17:12 EDT 2018


On 12Jun2018 07:51, Tamara Berger <brgrt2 at gmail.com> wrote:
[... snip ...]
>One more thing about PEP8. My workbook is a bit skimpy on details. Is there a 
>quick way to make the edits

PEP8 is a style recommendation for Python code:

  https://www.python.org/dev/peps/pep-0008/

It is followed pretty rigorously in the Python standard library, and most 
Python code follows a lot of it as a matter of good practice, in that (a) it is 
a fairly good style, producing easy to read code and (b) when everyone uses the 
same or similar styes, we all find other people's code easier to read.

But it is not enforced.

There are several "lint" tools around which will look at your code and complain 
about violations of PEP8 and various other constraints generally held to be 
good to obey, particularly some kinds of initialisation errors and other 
practices that while syntacticly legal may indicate bugs or lead to header to 
debug or maintain code.

Also, some text editors have facilities for autostyling code, sometimes as you 
type it and sometimes as a final step when you save the modified file.

For example, there are tools like autopep8 (https://pypi.org/project/autopep8/) 
which will modify python code directly to apply the PEP8 style.

Personally, I run a few lint commands against my Python code by hand, and hand 
repair. Typical workflow goes:

- modify code for whatever reason (add feature, fix bugs, etc) and test

- when happy, _then_ run a lint tool and tidy up most of what it reports

- _then_ instal the code where other things may use it (eg pip install)

My personal kit has a "lint" shell script:

  https://bitbucket.org/cameron_simpson/css/src/tip/bin-cs/lint

which runs my preferred linters against code files, and for Python it runs:

- pyflakes: https://pypi.org/project/pyflakes/

- pep8: https://pypi.org/project/pep8/

- pylint: https://pypi.org/project/pylint/, 
  https://pylint.readthedocs.io/en/latest/

These can all be installed using pip:

  pip install --user pyflakes pep8 pylint

As you can see from my lint script I run them with various options that 
oveeride their default checks to better match my preffered code style.

>or am I supposed to root around for my module and make the edits one by one?

Finally, no you don't normally root around and change an installed module.  
Instead, modify your original copy and reinstall the newer version!

Cheers,
Cameron Simpson <cs at cskk.id.au>



More information about the Python-list mailing list