Python Forum

Full Version: Options for retaining persistent data?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Other than using a small text file and updating it with data when variables change value, what mechanisms exist to retain data between system reboots?

on a raspberry pi-z0 i have a cronned job pinging for a wifi connection and rebooting the system on failure,
However now i want to run a small python script to respond to mqtt messages.


As the script is intended to raise alarms under numerous conditions a number of which reference the previously received payload its time of arrival and contents, or lack of.

And in order to avoid raising false alarms keeping a record of the last payload and its time of arrival that will survive a system reboot and restart of the script as a python newbie i am considering a simple text file update and check for existence/read on startup.

But I was wondering if there was a more elegant built in feature or library i could employ instead? or have i wasted a hour or so googling the wrong search terms completely??
persistent data is any database. Whether its a text file, json, or MySQL. For something simple like this i would just do json. Its human readable, as well as more adaptable than a text file if you want to add more and more later on.
https://pymotw.com/3/json/
In addition, any programming language talks JSON.
Thanks, a file it is then, though i thought it worth checking ..
Thanks, a file it is then, though i thought it worth checking ..

Thanks, a file it is then, though i thought it worth checking ..