Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Will the list delete its values after the session is done?

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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…

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading