Python3 Track Code error

I have been recently working on the Python3 pro track, in specific the files portion. However, once I got to lesson 8 and copypasted the code into vscode in order to make sure that it worked, I ran into an error, despite it working in CodeCademy:
import csv

list_of_cool_facts =
with open(‘cool_csv.csv’,newline=’’) as cool_csv_file:
cool_csv_dict = csv.DictReader(cool_csv_file)
for row in cool_csv_dict:
print(row[‘Cool Fact’])

The correct result is printed out in the terminal here, yet in vscode I get a key error. Would anyone be able to tell me why?
Learn Python 3 - Files Lesson 8

Hi and welcome to the forums!

Would you be able to copy and paste the specific error you are getting, as the code seems to work correctly for me in VS Code, thanks.

Traceback (most recent call last):
File “c:/Users/maxim/PythonStuff/CodeCademyLessons/Files/”, line 30, in
print(row[‘Cool Fact’])
KeyError: ‘Cool Fact’

Thanks for the reply

This implies that the key Cool Fact does not exist. Is it possible that your indentation is off in the VS Code file which is causing the check to run after the file has been closed? Perhaps a screenshot of exactly what the code looks like in VS Code would be useful to identify the issue, as your code as is seems to be working fine for me.

1 Like

I think the issue is that i’m not using the exact same csv file as here, but i’m not sure where i would find that

I got it to work, turns out I just didn’t get what a csv file was, as in Comma seperated file and had the wrong format pasted in lol

1 Like