Use config.has_section() instead of a separate dict

This commit is contained in:
Amit Chakradeo 2011-02-18 06:47:13 -08:00
parent d7c771bfbc
commit 9de21094a8

View File

@ -11,12 +11,10 @@ def csv2config(input, config=None):
config = ConfigParser() config = ConfigParser()
reader = csv.DictReader(input) reader = csv.DictReader(input)
d = {}
for row in reader: for row in reader:
section = row[reader.fieldnames[0]] section = row[reader.fieldnames[0]]
if not d.get(section): if not config.has_section(section):
config.add_section(section) config.add_section(section)
d[section] = 1
for name, value in row.items(): for name, value in row.items():
if value and name != reader.fieldnames[0]: if value and name != reader.fieldnames[0]:
config.set(section, name, value) config.set(section, name, value)