I'm following an example in a book and receiving an error. I have two files. One is named nobel_winners.csv and the other test.py I am trying to open nobel_winners.csv from test.py.
The contents of nobel_winners.csv is:
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}
]
from my test.py, I'm using f = open('nobel_winners.csv', 'w')
then cols = nobel_winners[0].keys()
. The program then throws:
NameError: name 'nobel_winners' is not defined.
What is going awry here?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…