[Python-bugs-list] [ python-Bugs-830449 ] Config parser don't raise DuplicateSectionError when reading

SourceForge.net noreply at sourceforge.net
Sun Oct 26 16:18:37 EST 2003


Bugs item #830449, was opened at 2003-10-26 13:20
Message generated for change (Comment added) made by johahn
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=830449&group_id=5470

Category: Python Library
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Miki Tebeka (tebeka)
Assigned to: Nobody/Anonymous (nobody)
Summary: Config parser don't raise DuplicateSectionError when reading

Initial Comment:
According to the documentation of ConfigParser
"DuplicateSectionError" it is raised if multiple
sections with the same name are found.

In the code this is not the case (it continues to
update the section with the same name (see
ConfigParser.py line 447).

Either fix the code (which I prefer :-) of the
documentation.

Miki

----------------------------------------------------------------------

Comment By: Johan M. Hahn (johahn)
Date: 2003-10-26 22:18

Message:
Logged In: YES 
user_id=887415

I hereby confirm the bug and I've included some sample code 
of it as well. Though I don't know which solution is the best. 
Fixing the code might break some production code that uses 
duplicate sections and it is therefor easier to just change the 
documentation. I also don't see reason to why they should be  
disallowed in the first place.

>>> import ConfigParser
>>> cp = ConfigParser.ConfigParser()
>>> from StringIO import StringIO
>>> fp = StringIO("""
;
[section1]
var1=option1
[section2]
var2=option2
[section1]
var3=option3
""")
>>> cp.readfp(fp)
>>> [x for x in cp.items('sec1')]
[('var1', 'option1'), ('var3', 'option3')]
>>> 

...johahn

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=830449&group_id=5470



More information about the Python-bugs-list mailing list