2014年9月10日 星期三

Python, Parse key, value pair without section

import StringIO
import ConfigParser

ini_path = "key_value_file_name"
ini_str = '[fakesection]\n' + open(ini_path).read()
ini_fp = StringIO.StringIO(ini_str)
config = ConfigParser.RawConfigParser()
config.readfp(ini_fp)
print config.items('fakesection')

沒有留言: