[Tutor] conventions for establishing and saving default values for variables

Jeff Johnson jeff at dcsoftware.com
Tue Jun 15 17:18:54 CEST 2010


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
jeff at dcsoftware.com



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100615/f876531f/attachment.html>


More information about the Tutor mailing list