ConfigObjError issue

417 views
Skip to first unread message

Mike Driscoll

unread,
Jan 4, 2010, 1:17:37 PM1/4/10
to pythonutils
Hi,

I have a vendor-supplied INI file that I was hoping ConfigObj could
read. However, I get the following traceback when I try to load it:

Traceback (most recent call last):
File "C:\Program Files\Wing IDE 3.2\src\debug\tserver\_sandbox.py",
line 1, in <module>
# Used internally for debug sandbox under external interpreter
File "c:\python25\lib\site-packages\configobj-4.6.0-py2.5.egg
\configobj.py", line 1219, in __init__
self._load(infile, configspec)
File "c:\python25\lib\site-packages\configobj-4.6.0-py2.5.egg
\configobj.py", line 1302, in _load
raise error
configobj.ConfigObjError: Parsing failed with several errors.
First error at line 62.

The INI file is pretty standard with everything in a section of its
own. The line that ConfigObj doesn't seem to like is in the middle of
the first section where there is just a semi-colon. Here is a snippet:

<snip>

AllowTesting = N
;
LogoFile =

</snip>

There are a couple more lines in the first section that are also like
this. Is there some way to make ConfigObj ignore those lines?

Thanks,

- Mike

Michael Foord

unread,
Jan 4, 2010, 1:27:04 PM1/4/10
to pytho...@googlegroups.com

Not directly, a semi-colon on its own is invalid syntax for ConfigObj.

You could strip them out with something like:

infile = [line for line in open(filename).readlines() if
line.strip() != ';']

All the best,

Michael

> Thanks,
>
> - Mike
>
> --
>
> You received this message because you are subscribed to the Google Groups "pythonutils" group.
> To post to this group, send email to pytho...@googlegroups.com.
> To unsubscribe from this group, send email to pythonutils...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/pythonutils?hl=en.
>
>


--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog


Mike Driscoll

unread,
Jan 4, 2010, 1:45:18 PM1/4/10
to pythonutils

Good idea, but I can't tell if their program needs those semi-colons
for its parser or not. I tried removing them just to see if ConfigObj
would finish parsing the file, but it doesn't like this line either:


System1 = SQL Sleuth,\\network\path\S9,,1,Default Database,,N,N,Y,


I can just use WriteProfileVal from the win32api module to do this
editing, but I had hoped to use ConfigObj as it's much cleaner. Oh
well. I should have known that this vendor's INI files would be far
from standard.

Thanks for your prompt reply!

- Mike

Michael Foord

unread,
Jan 4, 2010, 1:50:19 PM1/4/10
to pytho...@googlegroups.com

Right. The ConfigObj syntax is not extensible and hard to change
unfortunately. If anyone wants to write a pluggable grammar for it I
would be very happy though. :-)

> System1 = SQL Sleuth,\\network\path\S9,,1,Default Database,,N,N,Y,
>
>
>

That's being parsed as a list value - and it's badly formed. You could
try switching list values off.

All the best,

Michael

> I can just use WriteProfileVal from the win32api module to do this
> editing, but I had hoped to use ConfigObj as it's much cleaner. Oh
> well. I should have known that this vendor's INI files would be far
> from standard.
>
> Thanks for your prompt reply!
>
> - Mike
>

Reply all
Reply to author
Forward
0 new messages