Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PEP8 space after a comma

I'm doing code review, and seeing method declarations like that:

def __init__(self,data):

I always thought that it should be formatted like this:

def __init__(self, data):

But then I checked PEP 0008 and see no exact statement about that. There is guide about whitespace around operators, and inside parentheses, but no about comma separated list.

If it is not described in PEP8, probably there is some unwritten convention about this? Why I was convinced that this was in PEP8? Shoud PEP8 be updated?

like image 262
Bunyk Avatar asked Jul 31 '15 08:07

Bunyk


People also ask

What does the statement a foolish consistency is the hobgoblin of little minds mean in the context of coding in Python?

A Foolish Consistency is the Hobgoblin of Little Minds One of Guido's key insights is that code is read much more often than it is written. The guidelines provided here are intended to improve the readability of code and make it consistent across the wide spectrum of Python code.

Does Python use tabs or spaces?

While the Python style guide does say spaces are the preferred method of indentation when coding in Python, you can use either spaces or tabs.

Is PEP8 mandatory?

Pep8 is a coding standard and Style Guide for readability and long-term maintainability. It's not a requirement for your code to work, just a good coding practice you should follow. There are also some automated tools you can use to help make your source code pep8 and other linters. Here's an example of one.


1 Answers

I can't find the corresponding sentence in PEP8 as well, but I guess the reason that most people believe this rule is in PEP8 is pip pep8.

According to their document:

E231 missing whitespace after ‘,’

As most people use this as their style checker, it is easy to be convinced that the rule is really in PEP8.

like image 90
Gary Sham Avatar answered Sep 25 '22 18:09

Gary Sham