Configuration Files
M.E.Farmer
mefjr75 at hotmail.com
Sun Dec 26 02:38:31 EST 2004
Here are two functions that show how to use ConfigParser.
py>def ConfigWrite(key, value, section, cfgpath):
... import ConfigParser, pprint
... parser=ConfigParser.ConfigParser()
... cfg = open(cfgpath,'w')
... parser.add_section(section)
... Pretty = pprint.PrettyPrinter()#optional
... value = Pretty.pformat(value)#optional
... parser.set(section,key,value)
... parser.write(cfg)
... cfg.close()
py>def ConfigReader(key, section, cfgpath):
... import ConfigParser
... parser=ConfigParser.ConfigParser()
... parser.read(cfgpath)
... return parser.get(section,key)
Hope that helps...now *where* are those sugar cookies
M.E.Farmer
More information about the Python-list
mailing list