Closed GoogleCodeExporter closed 8 years ago
From: David Ortega
Date: Wed, 18 Oct 2006 12:22:17 +0200
Subject: Bug
Hello, trying your library I've found a little bug. I proceed to explain
you. When I try to delete a section I receive this message:
>>> from compat import ConfigParser
>>> cfg = ConfigParser()
>>> cfg.add_section("500")
>>> cfg.sections()
['500']
>>> cfg.remove_section("500")
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "compat.py", line 175, in remove_section
del self.data[section]
File "iniparser.py", line 377, in _delitem_
self._data.contents.remove(self._sections[key]._lineobj)
ValueError: list.remove(x): x not in list
This error comes from the line 377 of iniparser.py. In this line you try
to delete an item from a list, but the object that you try to pass is
incorrect. The line says:
self._data.contents.remove(self._sections[key]._lineobj)
self._sections[key] returns a section object, this object don't have the
attribute _lineobj, but have _lines. In this way we could put _lines[0]
for obtain lineobj. The line looks now like this:
self._data.contents.remove(self._sections[key]._lines[0])
and all runs correctly.
Greetings.
Original comment by psobe...@gmail.com
on 15 Jul 2007 at 11:27
From: "Gregory, Matthew"
Date: Mon, 12 Feb 2007 16:17:55 -0800
Subject: newbie question about cfgparse
Hi Paramjit,
Apologies for such a trivial question; I am new to Python, but have
found your cfgparse to be very useful in preserving comments and order
in an ini file.
However, I cannot figure out how best to remove sections from an
ini_namespace once loaded. I see from your examples that it is trivial
to remove sections from a basic_namespace instance, but when I convert
that over into a ini_namespace instance and try "del", it raises the
error "ValueError: list.remove(x): x not in list".
Here is what I've done:
from cfgparse.iniparser import ini_namespace
from cfgparse.config import basic_namespace
n = basic_namespace()
n.playlist.expand_playlist = True
n.ui.display_clock = True
n.ui.display_qlength = True
n.ui.width = 150
= ini_namespace()
i.import_namespace(n)
del i.playlist
The last line raises the error. Any guidance you could give would be
much appreciated.
thanks, matt
Original comment by psobe...@gmail.com
on 15 Jul 2007 at 11:31
Logic for deleting sections was broken. Fixed in svn #44.
Regarding the first comment - calling remove_section() on a non-existent
section should not raise a
NoSectionError. It should return false.
Original comment by psobe...@gmail.com
on 16 Jul 2007 at 12:36
Original issue reported on code.google.com by
psobe...@gmail.com
on 15 Jul 2007 at 11:15