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
27.1k9 gold badges58 silver badges80 bronze badges
asked Apr 23, 2022 at 2:54
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 CStephen C
694k94 gold badges798 silver badges1210 bronze badges
1
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
PyCharm displays a PEP8:W292 warning, as shown in Figure 1.
Figure 1 PEP8: W292 Warning
1 PEP
PEP is the abbreviation of Python Enhancement Proposal, that is, Python Enhancement Proposal. It includes naming conventions, annotation rules, and programming recommendations for Python programming. The W in W292 means Warn, which means warning. That is to say, the No. 292 warning in PEP8 is «There must be a new line at the end of the file», and there is no new line in the code in Figure 1, so there will be a warning.
2 processing method
2.1 Simple processing
As can be seen from Figure 1, click «Alt+Shift+Enter» to add a new line at the end of the file, making the warning disappear.
2.2 More processing methods
Click «Alt+Enter» to pop up more processing methods, as shown in Figure 2.
Figure 2 More processing methods
2.2.1 Modify format
The first item in Figure 2, the «Reformat the file» option re-processes the format of the file, that is, adding a new line at the end, which is the same as clicking «Alt+Shift+Enter». «Edit inspection profile setting» option, open the «Inspection» settings dialog box, as shown in Figure 3.
Figure 3 Check dialog box
2.2.2 Modify settings
The second item in Figure 2, the «PEP 8 coding style violation» option is used to pop up a prompt message when the code does not conform to the PEP8 rules. If this option is canceled, the prompt message will not pop up, and when the file is opened again later, the message will not pop up again.
2.2.3 Ignore the prompt
The third item in Figure 2, the function of the «Ignore errors like this» option is to ignore the prompt. After selecting this item, the prompt message will not pop up, but when the file is opened again, the warning message will still exist.
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.
Go to Hyperskill
Warning PEP 8: W292 no newline at end of file in PyCharm
I have been using Intellij for a while but I just downloaded PyCharm to start working on the Python side of JetBrains Academy. So far, the first exercises that I have done with print() are always highlighting a warning in the closing parenthesis of print with the message PEP 8: W292 no newline at end of file and I don’t know what this means, did I do something wrong while installing or configuring PyCharm? If it is irrelevant, is there a way to stop from showing? Thanks!