I got the same error below when using Flake8:
no newline at end of fileFlake8(W292)
Because I didn't add one blank line after the last code print(math.pi)
as shown below:
1 import math
2
3 print(math.pi)
So, I added one blank line after the last code print(math.pi)
as shown below, then the error was solved:
1 import math
2
3 print(math.pi)
4
Actually, I saw PEP 8 but I could not find why to add one blank line after the last code but the error below also occurred in the same situation when using Pylint:
Final newline missingPylint(C0304:missing-final-newline)
So, I think that adding one blank line after the last code is recommanded in Python even though I don't know the reason.
In addition, if you add more than one blank lines after the last code print(math.pi)
as shown below:
1 import math
2
3 print(math.pi)
4
5
Then, you get the errors below with Flake8 and Pylint respectively:
blank line at end of fileFlake8(W391)
Trailing newlinesPylint(C0305:trailing-newlines)