2

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
  • 1
  • 1
  • Erm... I'm not used to this syntax, maybe try: `hfile = open(hfile_name)` instead of using the `newline` argument? Just seems a little suspicious... – Ben Quigley Feb 21 '17 at 03:01
  • @Benjamin Regardless, the question is about W-warnings (not really errors, unless one chooses such) as an applied style check. – user2864740 Feb 21 '17 at 03:03
  • @GedAWizardofEarthSea It might be a minor quirk in the tool - and it might more appropriate to ask on the specific mailing list / project trackers. Anyway .. what about changing the file to end in a statement such as `sys.exit(0)`? And, Python 2 or 3 (since `print` is involved)? – user2864740 Feb 21 '17 at 03:05
  • @user286 you are correct, it is a warning. I noted (perhaps incorrectly) it as an error as I did not receive the desired result the first time around. I however ran it a second time and did receive the desired output... – GedAWizardofEarthSea Feb 21 '17 at 03:38
  • 1
    Its likely the first warning (W391) was because you were missing a blank line at the end of the file, and when you added one, it had extra whitespace, because most IDEs will indent the next line automatically for you, giving W293. This has nothing to do with your specific code, and nothing really to do with Python, but more to do with your text editor (IDE), which you didn't mention... – darthbith Feb 21 '17 at 12:28
  • @darthbith I am utilizing Spyder v3 within Anaconda Navigator – GedAWizardofEarthSea Feb 21 '17 at 13:19

1 Answers1

0

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.

gmauch
  • 1,316
  • 4
  • 25
  • 39