I am writing and testing a function for opening a .csv file and save information in a dictionary, instead of using import csv.
The csv file is like:
16SAP,12/02/24,sapin-9,MATEYIJDNS
FAS1,01/02/21,fasiculata,MTYEUSOLD
EDS5,10/20/20,epsilon,MHGSJDKDLSKDKDJS
etc....
and .csv file has a (,) separated format and 4 fields: identifier, date, name and sequence, respectively.
My code is:
def dicfromcsv(csv_file):
with open('csv_file', 'r') as f:
d = {}
l = f.read().split(',')
for i in l:
values = i.split(':')
d[values[0]] = values[1], values[2], values[3], values[4]
dicfromcsv('PDB.csv')
But it doesn't function.
Thank in advance
:in your file, what isi.split(':')supposed to do?csvmodule? docs.python.org/3/library/csv.htmllis not a line, it's one of the comma-separator fields in the file.with open('csv_file'is going to try to open a file literally named "csv_file"