Working with CSV

https://www.codecademy.com/courses/learn-python-3/lessons/learn-python-files/exercises/reading-a-csv

**I was trying to work with this exercise on my own machine and I couldn’t read the CSV file even though I creat it in the same folder as the python file **

import csv
with open("users.csv", newline="") as users_csv:
    user_reader = csv.DictReader(users_csv)
    for row in user_reader:
        list_of_email_addresses.append(row["Email"])

print(list_of_email_addresses)

I get this error:
FileNotFoundError: [Errno 2] No such file or directory: ‘users.csv’

Well, with the help of StackOverflow I was able to figure out that I have to import ‘os’ to get ‘cwd’

MY Question is :
Why am I able to see the right output on the terminal but not on the OUTPUT section?

I’m not familiar with the IDE but did you run that script in the TERMINAL tab? I’d assume that’s the most likely reason for output appearing there and perhaps using an inbuilt run command would send the output to the OUPUT tab (at a guess). My only other guess would be if there was a setting to alter it but I’m afraid I don’t know for certain.

It’s worth noting that os.cwd() returns a unicode string of the (c)urrent (w)orking (d)irectory. It doesn’t change the working directory. You’d need something like os.chdir() for that.

1 Like