W292 python ошибка

I’m having trouble understanding what «No newline at end of file» means exactly.

I’ve got

if __name__ == "__main__":
    app.run(
        host=os.environ.get("IP", "0.0.0.0"),
        port=int(os.environ.get("PORT", "5000")),
        debug=False)

The error is pointing to the last line

debug=False

Can someone help explain to me why I’m getting this invalid error and offer a solution to solve it. Thanks

wjandrea's user avatar

wjandrea

27.2k9 gold badges59 silver badges80 bronze badges

asked Apr 23, 2022 at 2:54

Ryu's user avatar

7

It means exactly what it says. There is no recognizable newline at the end of the file. The last character is the ) … or maybe a TAB, or SPACE, or a line terminator for a different platform.

Solution: open the file in an editor, add a newline at the end, save and close the file.


I’ve tried that, I had a new line after it and I get «blank line contains whitespace» error.

So what you had was a line consisting of white space (SPACE or TAB characters) followed by a newline. Use your editor to get rid of that line.

The style checker wants the last line of the file to end with the newline character, and to have no trailing whitespace on that line.

answered Apr 23, 2022 at 3:05

Stephen C's user avatar

Stephen CStephen C

694k94 gold badges798 silver badges1210 bronze badges

1

Files should end with a newline.

Anti-pattern

Imagine the example below is an entire file.

import os

BASE_DIR = os.path.dirname(os.path.abspath(__file__))

Best practice

Imagine the example below is an entire file.

import os

BASE_DIR = os.path.dirname(os.path.abspath(__file__))
# This is a new line that ends the file.

No newline at end of file

Files should end with a newline.

Anti-pattern

Imagine the example below is an entire file.

import os

BASE_DIR = os.path.dirname(os.path.abspath(__file__))

Best practice

Imagine the example below is an entire file.

import os

BASE_DIR = os.path.dirname(os.path.abspath(__file__))
# This is a new line that ends the file.

Why I am getting W292 error (warning) in python when print(rows) from a .csv? The last line is the one that throws the error (warning). The expected output is the .csv values from the file.

If I then add another line after print(rows) I receive this error «W293 blank line contains whitespace W391 blank line at end of file»

import csv

hfile_name = "Hospital_Readmissions_Reduction_Program.csv"
hfile = open(hfile_name, newline='')
hdata = csv.reader(hfile, delimiter=',', quotechar='"')

for rows in hdata:
    print(rows)

I have found some additional threads on this error (warning), but not a definitive solution…
PEP8: conflict between W292 and W391

https://github.com/PyCQA/pycodestyle/issues/286

Community's user avatar

asked Feb 21, 2017 at 2:59

GedAWizardofEarthSea's user avatar

6

As stated in the comments the problem you were facing is much probably IDE specific and not a Python issue.

I pasted your code in another IDE (Pycharm Community Edition) and also on an online Python code checker and in no case the warning you mentioned appeared.

Anyway, since it’s a warning only, you can run your code without any further issues.

answered Jun 18, 2019 at 13:00

gmauch's user avatar

gmauchgmauch

1,3064 gold badges25 silver badges39 bronze badges

I am Robert Laursoo. MSc in pharmacy with 6+ years of pharma marketing experience, MBA, IT student, living in Tallinn, Estonia. Here I write mainly about school, education and how I learn to code.

Learn more about me.

Search for:

Bookmarks

  • SSH tag (all posts)
  • SSH Ubuntu
  • SSH WordPress
  • Algorütm Podcast
  • Restart Podcast

Topics to write about

  • Estonian tech podcasts
  • Toggl for time management
  • How to get scholarship (with bigger probability)
  • Partial automation of customer feedback requests by using Smaily

List of interesting companies

Because from time to time I sometimes forget some of them (aphabetical order).

Devtailor
Fortumo
Icefire
Iglu
NetGroup
Proekspert
Thorgate
Twilio
Web Expert

Also: CGI, Fujitsu, Playtech
Web: Hable, Play

Recent Posts

  • wp cli delete orders older than…
  • wp cli to delete unattached images
  • Use specific php version in cli
  • The Best Pomodoro Timer for Android
  • Disable xdebug and fix Postman output

Categories

  • Coding
  • dotnet
  • E-kaubandus
  • Excel
  • Laravel
  • Linux
  • Magento
  • Notes
  • Prestashop
  • Python
  • Random
  • School
  • Sport
  • Windows
  • WooCommerce
  • WordPress

Понравилась статья? Поделить с друзьями:
  • W220 ошибка климата 1000
  • W220 ошибка абс
  • W220 как скинуть ошибки климата
  • W211 ошибка аккумулятора красным
  • W211 ошибка p0140