1
Hello. I am following the reading of the book Data Visualization with Python and Javascript from Scratch by Kyran Dale (O'Reilly). In the following code, it is understood that a . csv file should be saved, using the Python csv library.
Using Anaconda2
import csv
import os.path
nobel_winners = [
{'category': 'Physics',
'name': 'Albert Einstein',
'nationality': 'Swiss',
'sex': 'Male',
'year': 1921},
{'category': 'Physics',
'name': 'Paul Dirac',
'nationality': 'British',
'sex': 'Male',
'year': 1933},
{'category': 'Chemistry',
'name': 'Marie Curie',
'nationality': 'Polish',
'sex': 'Female',
'year': 1911}
]
mypath = os.path.abspath(os.path.dirname(__file__))
path = os.path.join(mypath, './data/nobel_winners.csv')
with open(path,'wb') as f:
fieldnames = nobel_winners[0].keys()
fieldnames.sort()
writer = csv.DictWriter(f,fieldnames=fieldnames)
writer.writeHeader()
for w in nobel_winners:
writer.writerow(w)
However, what appears to me in pylint is the exit:
Module 'csv' has no 'Dictwriter' Member
How can I fix this?
The book uses Python 2.7 as default, but even in the documentation I found nothing that marked this member as deprecated or something like that.
Your code is correct, however, it still shows the same message. In addition to this, I realized that I was actually running Anaconda2 (python 2.7). To try one last time, I’m downloading Anaconda3. Thank you for your reply, which incidentally was quite accurate (I’m still getting used to the syntax and language of python).
– Isaias Velasquez
You must be making some other mistake (or it’s different versions), here running without errors. Detail: With anaconda you can have several versions of python. You can even install anaconda 3 and run python 2.7 and all versions of the packages you have in the book you are studying. See that answer
– Sidon
Actually the newest version of anaconda is 4.x.
– Sidon
In fact, I was with the Python version problem, now I have updated Anaconda, and it worked. Thank you very much!
– Isaias Velasquez