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
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
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
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
>