I’m trying to append some answers to a list, and that works. But what happens when the session is over? Will that be deleted from the list?
The issue is, when I run the code again, looks like the list is empty.
Any suggestions on how to avoid this?
>Solution :
I am assuming that by session your mean the program…that said, one way, more simple one, would be to pass the data to a file and read it back when your program initializes again:
#import json
your_list = [# your data here...]
# open file in write mode
with open(r'your/path/here', 'w') as fp:
for item in your_list:
# write each item on a new line
fp.write(f"{item}\n")
#json.dump(your_list,fp)
#then when your program starts...
with open(r'your/path/here', 'r') as fp:
your_list.extend(fp.read().splitlines())
#your_list = json.load(fp)
Of course you could create a database but this is just quick and dirty since no other requesits where specified in the question.Like mentioned juanpa for best practices you could use json but again as i said in the answer this was just quick and dirty…