構成ファイルを辞書に解析する方法についての良いスニペットを以前に受け取りましたが、構成ファイルを解析できない理由を見つけることができないようです (コメントの外にタプルがないため)
私のエラーメッセージ、
Traceback (most recent call last): File "test2.py", line 9, in
<module>
CONFIG_DATA[section_name][item_name] = cfg.get(section_name, item_name) File "C:\Python27\lib\ConfigParser.py", line 614, in get
option = self.optionxform(option) File "C:\Python27\lib\ConfigParser.py", line 374, in optionxform
return optionstr.lower() AttributeError: 'tuple' object has no attribute 'lower'
コード、
import ConfigParser
from pprint import pprint
cfg = ConfigParser.ConfigParser()
cfg.read('config2.cfg')
CONFIG_DATA = {}
for section_name in cfg.sections():
CONFIG_DATA[section_name] = {}
for item_name in cfg.items(section_name):
CONFIG_DATA[section_name][item_name] = cfg.get(section_name, item_name)
pprint(CONFIG_DATA)
私の設定ファイル http://pastebin.com/UKnrXFGR