In PSET6 DNA, I have to read the CSV file.
I use
with open("P:\Code\Python\dna\databases\small.csv") as csvfile: #open on my PC
dna_db = csv.DictReader(csvfile)
for row in dna_db:
print(row)
The dna_db seeems ok:
{'name': 'Alice', 'AGATC': '2', 'AATG': '8', 'TATC': '3'}
{'name': 'Bob', 'AGATC': '4', 'AATG': '1', 'TATC': '5'}
{'name': 'Charlie', 'AGATC': '3', 'AATG': '2', 'TATC': '5'}
I can't find how to exploit the new dictionary (dna_db). I thought it's was a nested dictionary, but Maybe it's just 3 dictionaries.
I've try with:
print(dna_db[0][0]) => TypeError: 'DictReader' object is not subscriptable
print(dna_db[0]['name']) => TypeError: 'DictReader' object is not subscriptable
Someone could help me with the code or the logic to extract 1 value? For exemple 'Bob' or the '1' ?
Thanks