私はConfigParserモジュールを使用します。これは、あなたの例に対してかなり読みやすく、ユーザーが編集可能な出力を生成します。
[ボブ]
color_scheme: 青
イギリス人: はい
[ジョー]
color_scheme: それは「色」です、ばかげています!
イギリス人: いいえ
次のコードは、上記の構成ファイルを生成し、それを出力します。
import sys
from ConfigParser import *
c = ConfigParser()
c.add_section("bob")
c.set("bob", "colour_scheme", "blue")
c.set("bob", "british", str(True))
c.add_section("joe")
c.set("joe", "color_scheme", "that's 'color', silly!")
c.set("joe", "british", str(False))
c.write(sys.stdout) # this outputs the configuration to stdout
# you could put a file-handle here instead
for section in c.sections(): # this is how you read the options back in
print section
for option in c.options(section):
print "\t", option, "=", c.get(section, option)
print c.get("bob", "british") # To access the "british" attribute for bob directly
ConfigParser は文字列のみをサポートすることに注意してください。そのため、上記のブール値のように変換する必要があります。基本の概要については、 effbotを参照してください。