PyCharm shows "PEP8: expected 2 blank lines, found 1"
87,834
Solution 1
Just add another line between your function definitions :
1 line :
2 lines:
Solution 2
This is a pretty common question within the python community. After the release of PEP 8, new formatting styles were accepted into python. One of them states that after the definition of a class or function there must be two lines separating them. As such:
def yadayada:
print("two lines between the functions")
def secondyadayada:
print("this is the proper formatting")
So, you should never do it like:
def yadayada:
print("two lines between the functions")
def secondyadayada:
print("this is the proper formatting")
Or else PyCharm will throw that error at you.
![march_seven](https://lh4.googleusercontent.com/-PB4V5H2o0t8/AAAAAAAAAAI/AAAAAAAAACA/d_G7amrFCfo/photo.jpg?sz=256)
Author by
march_seven
Updated on July 09, 2022Comments
-
march_seven almost 2 years
Consider the following code:
def add_function(a, b): c = str(a) + b print "c is %s" % c def add_int_function(c, d): e = c + d print "the vaule of e is %d" % e if __name__ =="__main__": add_function(59906, 'kugrt5') add_int_function(1, 2)
It always shows me: "expected 2 blank lines ,found 1" in a
add_int_function
, but not in theadd_function
.When I add two spaces in front of the
def add_int_function(c, d):
there is a error showsunindent does not match any outer indentation level
in the end ofadd_function
: -
Kennet Celeste almost 7 years@march_seven if this solved your issue you can accept the answer so that the others will immediately find out this solved the problem
-
Franz Deschler over 6 yearsWhy is this necessary? What happens if there is just 1 line between the functions?
-
TT-- over 6 years@FranzDeschler nothing happens, it just does not conform to the style guide, python.org/dev/peps/pep-0008/#blank-lines
-
Leo Ufimtsev almost 5 yearsIs it possible to turn this pep8 behaviour off?
-
Alan Bagel almost 3 years@Leo Ufimtsev Go to Settings -> Editor -> Inspections -> Python -> PEP 8 coding style violation. Then press the check mark to disable it. You can also change the severity if you want to.
-
Gulzar over 2 years@grandBagel Some things are better left unknown