0

How can I define a list that is empty at first and append to it but not have it clear when I restart my app? I am using python language

The list has the proper values in it when the app is first ran, it is only when I restart my app that the list clears because of the empty list variable over rides the list that was just created. Thanks in advance

DevOps
  • 384
  • 1
  • 12
john
  • 23
  • 5
  • i am using the python language – john Apr 29 '18 at 00:47
  • 3
    There is no reason whatsoever your variables would be magically saved and loaded. Take some time to learn the basics. Then implement save and load features should you need them. – spectras Apr 29 '18 at 00:51
  • could i save a dictionary with that list in it to a file and get the values back that way? – john Apr 29 '18 at 01:01
  • 1
    Possible starting point: https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files – spectras Apr 29 '18 at 01:02
  • 1
    Possible duplicate of [Keep persistent variables in memory between runs of Python script](https://stackoverflow.com/questions/6687660/keep-persistent-variables-in-memory-between-runs-of-python-script) –  Apr 29 '18 at 02:06

1 Answers1

1

A list doesn’t get saved when closing a python program. If you want this you should save the list in a specific file and load this file everytime your python program opens. One of the basics of python is that lists, dictionairies etc don’t get saved on change or exit.

DevOps
  • 384
  • 1
  • 12