test.cnf
[db] addr : localhost user : user passwd : passwd [db2] addr : localhost user : user passwd : passwd
예제
#!/usr/bin/env python import ConfigParser config = ConfigParser.ConfigParser() config.read('test.cnf') for section in config.sections(): print section for option in config.options(section): print " ", option, "=", config.get(section, option) config.add_section("db3") config.set("db3", "addr", "addr") config.set("db3", "user", "user") config.set("db3", "passwd", "passwd") config.write(sys.stdout)
쉽군!