'How can I save an input value so I can retrieve it next time I run the code (Python)?

Is there an easy way for me to store user input data so next time I run the program, it considers the previous value assigned to a variable?

I want to create a program to add 1 absence every time I don't attend a class. However, I don't know how to store that data. Ex.: I added 1 absence, and next time I run the code and add another, I want the program to retrieve 2 and not 1.

absence = None
userinput = input("add absence:")
userinput = int(userinput)
if absence == None:
   absence = userinput
else:
   absence = absence+userinput
print(absence)


Solution 1:[1]

I am getting a feeling you dont want to set up and maintain a database for this, you could go with the approach of saving or persisting the data in a json or xml file to your local path (or a cloud location) and access it every time your code runs.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Anand Satheesh