I don't know what the error means for PEP8

Asked 2 years ago, Updated 2 years ago, 34 views

I read the PEP8 document, but it was my first time.
Honestly, I don't know how to fix it, so I would appreciate it if you could point it out.

Error Message

too many blank lines

Error Message Location

def popular_article(query1):

Code

def popular_article(query1):
    db=psycopg2.connect("dbname=news")
    c=db.cursor()
    c. execute(query1)
    results=c.fetchall()
    for in results:
        print("{0}--{1}views".format(e[0], e[1]))
    db.close()

Lines 55 to 57 exceed 79 characters, so
I made it into three lines, but I got the following error.

Error Message

line break before binary operator
missing space after', '

Error Message Location

 print(date.strftime('%B%d,%Y')
       + ' ' + '--' + ' '
       + str(round(per_err,1)))+'%'+'+'errors')

Code

default_percent(query3):
    db=psycopg2.connect("dbname=news")
    c=db.cursor()
    c. execute(query3)
    results=c.fetchall()
    for in results:
        date=(e[0])
        per_err=(e[1])
        print(date.strftime('%B%d,%Y')
               + ' ' + '--' + ' '
               + str(round(per_err,1)))+'%'+'+'errors')
    db.close()

Error Message

no newline at end of file

Error Message Location

 error_percent(query3)

Code

 if__name__=='__main__':
    print("The 3most popular articles of all time are:")
    popular_article(query1)
    print("\n")
    print("The most popular article authorities of all time are")
    popular_author(query2)
    print("\n")
    print("Days did more than 1% of requests lead to errors")
    error_percent(query3)

python python3

2022-09-30 16:34

1 Answers

Correct the error as it is.

  • too many blank lines
    • Probably a large number of empty lines before the function definition.Delete it. (Reference)
  • line break before binary operator
    • The binomial operator here points to +. You are getting an error because you are breaking a new line before +, so try to break a new line after +.
  • missing white space after','
    • round(per_err,1).
  • no newline at end of file
    • This means that there is no new line at the end of the file.Place an empty line at the end of the file (in fact, this may not work well for anything other than Python).
  • Probably a large number of empty lines before the function definition.Delete it. (Reference)
  • The binomial operator here points to +. You are getting an error because you are breaking a new line before +, so try to break a new line after +.
  • round(per_err,1).
  • This means that there is no new line at the end of the file.Place an empty line at the end of the file (in fact, this may not work well for anything other than Python).


2022-09-30 16:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.