Is there a way to save the variable value in python In case of power failure so when i run the program again it does not start from initial value but the value which was saved last.In the below code i am counting the number of times a button is pressed so can i save the value of age and start counting from the saved value insted of starting from 15.
import RPi.GPIO as GPIO
import time
age=15 //initialize for debugging
GPIO.setmode(GPIO.BCM)
GPIO.setup(25, GPIO.IN,GPIO.PUD_DOWN)
def led(channel): //funtion for increnment age
global age
age=(age+1)
print(age)
PIN 7 AND 3.3V
normally 0 when connected 1
GPIO.add_event_detect(25, GPIO.RISING, callback=led, bouncetime=1000 )
print(age)
try:
while(True):
time.sleep(1)
except KeyboardInterrupt:
GPIO.cleanup()
print (age)
print ("Exiting")