[Tutor] conventions for establishing and saving default values for variables
steve at pearwood.info
Tue Jun 15 15:40:38 CEST 2010
On Tue, 15 Jun 2010 10:27:43 pm Pete O'Connell wrote:
> Hi I was wondering if anyone could give me some insight as to the
> best way to get and save variables from a user the first time a
> script is opened. For example if the script prompts something like
> "What is the path to the folder?" and the result is held in a
> variable called thePath, what is the best way to have that variable
> saved for all subsequent uses of the script by the same user.
Others have already mentioned ConfigParser. You should also check out
plistlib, in the standard library since version 2.6.
Other alternatives include pickle, XML, JSON or YAML (although since
YAML is not part of the standard library, you will need to download a
package for it). On Windows you can write to the registry, although
since I'm not a Windows user I don't know how. Or if your config is
simple enough, you can just write your data to the file manually. But
honestly, you can't get much simpler than ConfigParser or plistlib.
More information about the Tutor