I have searched for a solution to this, but I have not been able to find one, weirdly.
I am opening a file with the following contents in it.
Alex,10,0,6,3,7,4
Bob, 6,3,7,2,1,8
I want to convert all the values in score_list from 1-4 index value to an integer. I have tried to do so with this following but it just doesn't work.
score_list = []
def opening_file():
counter = 0
with open('scores.txt', newline='') as infile:
reader = csv.reader(infile)
for row in reader:
score_list.append(row[0:5])
counter = 0
while counter != 5:
counter +=1
row[counter] = int(row[counter])
print (score_list)
opening_file()
but it doesn't work and just produces
[['Alex', '10', '0', '6', '3'], ['Bob', ' 6', '3', '7', '2']]
instead of [['Alex', 10, 0, 6, 3], ['Bob', 6, 3, 7, 2]]