[Tutor] need advice about a dictionary ({})

Steven D'Aprano steve at pearwood.info
Thu Sep 8 15:03:23 CEST 2011


Richard D. Moores wrote:

> But I'd like to put the lines of the dictionary in a text file so that
> I can add key/value items to it by writing to it with another script.

If you expect human beings (yourself, or possibly even the user) to edit 
the text file, then you should look at a human-writable format like these:


Good ol' fashioned Windows INI files:
     import configparser
JSON:  import json
PLIST: import plistlib
YAML:  download from http://pyyaml.org/wiki/PyYAML


If the ability to edit the files isn't important, then I suggest using 
the pickle module instead.





-- 
Steven



More information about the Tutor mailing list