I am trying to write a new row for each item in list_people with the name and age of the person. If there are 3 people in the list, my CSV should have 3 rows and 2 columns as shown below:
Joann 15
Maria 13
Peter 19
My CSV gives me 1 row and 6 columns as shown below:
Joann 15 Maria 13 Peter 19
Here is the code I am using.
row_lines=[]
for i in list_people:
info = inspect.getmembers(i)
name = info[1]
row_lines.append(name)
age = info[2]
row_lines.append(age)
with open('test.csv', 'w') as csvFile:
writer=csv.writer(csvFile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL, lineterminator='\n')
writer.writerow(row_lines)
What do I need to change so that it writes to a new row for each iteration of my loop (for each person in the list_people)?