I'm doing a python script that reads a CSV file. This is the code:
with open("DATABASE.csv", "r", newline="") as a:
csv_reader = csv.DictReader(a)
rows = list(csv_reader)
print(rows[2]["NAME"] rows[2]["SURNAME"])
The [2]
means that it read the second line of the file.
How can I replace it with a number chosen by the user?
If I save the user's choice into a variable and I insert the variable in the [ ]
it reply with TypeError: list indices must be integers or slices, not str
--
And other little thing: is there a way to delete a single line in the CSV?