Steven D'Aprano wrote:
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.
On Windows I create an ".ini" file in the user profile instead of the
registry. Windows API has GetPrivateProfileString and
WritePrivateProfileString. On Linux I use ConfigParser to read and write
to an ".ini" file in the home directory.
I have avoided the Windows registry completely. Obviously you could use
ConfigParser on Windows because of Python.
--
Jeff
-------------------
Jeff Johnson
j...@dcsoftware.com
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor