PyCharm shows “PEP8: expected 2 blank lines, found 1”

左心房为你撑大大i 提交于 2019-12-04 16:24:40

问题


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 aadd_int_function, but not in the add_function.

When I add two spaces in front of the def add_int_function(c, d): there is a error shows unindent does not match any outer indentation level in the end of add_function:


回答1:


Just add another line between your function definitions :

1 line :

2 lines:




回答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.




回答3:


I've been getting the same error and figured out how to get rid of it.

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

to rectify the error add another blank line, there should be two blank lines i.e blank lines between 34 and 37. see the rectified error image:



来源:https://stackoverflow.com/questions/40275866/pycharm-shows-pep8-expected-2-blank-lines-found-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!