snosniv <
[email protected]> wrote:
My script asks the user to enter a value which, if the user then
ticks a checkbutton, this value is retained for the next time the
script is opened.
I'm guessing I'd have to write back to the script, or is there a cleaner/simpler way?
That is /one/ way -- but you will immediately be thrust headfirst into 'self-modifying code' territory that way, and for modern OS's that
offer file ownership protections, if the user running the script does
not have write access to the actual script file, the write-back will
fail.
And, for true multi-user setups, even if the writes were to succeed,
writing back to the script itself would mean that user X+1 receives the
default that user X set. And this is probably not what you want.
The more usual way is to store this 'value' into a config file, owned
and accessible exclusively by the user running the script, and upon
startup the script first checks for presence of the config file, and if present, uses the value stored therein to 'pre-setup' the defaults.
And checking the box would create the config file (if it was not
already created at script startup anyway).
The 'ini' package in Tcllib can assist greatly with handling (read/write/create) of the actual config file.
Then you just have to pick a storage place. On Linux that would
likely best be ~/.config/Your-Scripts-Name-Here/defaults.ini (assuming
you picked to use the 'ini' package, and named the file 'defaults').
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)