Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Save variable to use it in next script execution
-
I search for a way to save a variable so that I can recall it in the next execution of the script. I want to use it like a counter. Or is there a way to interact with some kind of database? Any hints?
-
Read/write to a file, json, pickle, marshal, sqlite3, there are a million ways to do this but...
import contextlib, shelve file_name = 'my_shelve' # Pythonista will create '.bak', '.dat', and '.dir' files with contextlib.closing(shelve.open(file_name)) as d: print(d.setdefault('counter', 0)) d['counter'] += 1
-
Or pretend it is a password and use keychain.
-
-
Thanks for the information!