'I keep on getting a KeyError in Python

I keep on getting a KeyError and not sure what I'm doing wrong here??

    import csv
    
    list_of_email_addresses = []
    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"])


Solution 1:[1]

In python, you access a dictionary like this.

myDict = {1: "foo", 2: "bar"}
print(myDict[1], myDict[2])
>>> foo, bar

I imagine your CSV file doesn't have the column you're trying to access as a key and that's why a KeyError is being raised.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1