PyCharm shows "PEP8: expected 2 empty lines found 1"

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) 

He always shows me: "2 empty lines are expected , found 1" in the add_int_function function, but not in the add_function function.

When I add two spaces before def add_int_function(c, d): an error appears showing that unindent does not match any outer indentation level at the end of add_function :

enter image description here

enter image description here

+11
source share
3 answers

Just add another line between function definitions:

1 line:

enter image description here

2 lines:

enter image description here

+42
source

I get the same error and figured out how to get rid of it. error image

line 36 (see error image): def create_lottery_numbers (): contains a wavy line, because between 34 and 36 there is only one line of empty space, i.e. 35 error says: "two empty lines are expected, one is found"

To fix the error, add another empty line, there should be two empty lines, i.e. empty lines between 34 and 37. See the corrected error image:

rectified

0
source

This is a fairly common question in the python community. Since the release of PEP 8 in Python, new formatting styles have been adopted. One of them says that after defining a class or function, there should 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 this:

  def yadayada: print("two lines between the functions") def secondyadayada: print("this is the proper formatting") 

Or PyCharm will give you this error.

0
source

Source: https://habr.com/ru/post/1011745/


All Articles