I want to see what the keys of the reader
dictionary are so I use the print(key)
function. The result is all the lines of the dictionary. Why is that?
import csv
from sys import argv, exit
# Check if there are enough command-line arguments
if len(argv) != 3:
print("missing comment-line argument")
exit(1)
# Open the CSV file to read
with open(argv[1], "r") as csvfile:
reader = csv.DictReader(csvfile)
# Why don't the following lines print the keys but all the lines in the CSV file?
for key in reader:
print(key)
The result:
OrderedDict([('name', 'Alice'), ('AGATC', '2'), ('AATG', '8'), ('TATC', '3')])
OrderedDict([('name', 'Bob'), ('AGATC', '4'), ('AATG', '1'), ('TATC', '5')])
OrderedDict([('name', 'Charlie'), ('AGATC', '3'), ('AATG', '2'), ('TATC', '5')])