Shows how to convert a comma separated value (csv) string to a list of records, and then do some data processing. The csv strings usually come from csv files created by spreadsheets.
Example reading the data from a "csv_str.csv" file:
# convert to a list of records record_list =  with open ("csv_str.csv",'r') as fi: reader = csv.reader(fi,delimiter=',') for line in reader: name, age, weight, seniority, pay = line record = Persons(name, age, weight, seniority, pay) record_list.append(record)
Don't forget to import the csv library
Thanks for showing how to read the csv file directly. For testing purposes it was simpler to use the string in the code.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.