I want to delete a specific line that matches the argument and remove the line from the CSV file. I can't seems to find a solution.
The sample CSV data are as follows:
Apple, 1.0, 1.0
Banana, 2.1, 2.1
Carrot, 3.2, 3.2
Let's say I only want to remove the banana row, is is possible?
def delete_place(name):
file = open('data/db.csv', 'r')
reader = csv.reader(file)
for row in reader:
if name != row[0]:
return 'Place not found.', 400
else:
# todo: delete line in csv
return 'Place with name {} deleted.'.format(name), 200