Say I have the list
score = [1,2,3,4,5] and it gets changed while my program is running. How could I save it to a file so that next time the program is run I can access the changed list as a
I have tried:
score=[1,2,3,4,5] with open("file.txt", 'w') as f: for s in score: f.write(str(s) + '\n') with open("file.txt", 'r') as f: score = [line.rstrip('\n') for line in f] print(score)
But this results in the elements in the list being strings not integers.