Simple ini Config parser examples needed
clp at rebertia.com
Wed Dec 3 00:22:41 CET 2008
On Tue, Dec 2, 2008 at 2:51 PM, Glenn Linderman <v+python at g.nevcal.com> wrote:
> On approximately 12/2/2008 1:31 PM, came the following characters from the
> keyboard of Chris Rebert:
>> On Tue, Dec 2, 2008 at 1:18 PM, RON BRENNAN <rbrennan55 at hotmail.com>
>>> I have a very simple ini file that I needs parsed. What is the best way
>>> can parse an ini file that doesn't include sections?
*Bangs head against wall repeatedly*
I merely glossed the question and missed that all-important second
My apologies, I shouldn't write email before having coffee :)
Fortunately Tim followed quickly with the correct answer to the OP.
>>> As in:
>> Since it appears that ConfigParser requires at least one section
>> header, I'll assume the file starts with the following line:
>>> Thats it. Can anyone help me?
>> Completely untested:
>> import ConfigParser
>> config = ConfigParser.RawConfigParser()
>> config.get("main", "height") #==> "small"
> Of course the OP question was that the line you assume isn't there. But if
> the ini is simple, maybe it is short enough to read into a string, then
> prepend the line, then parse with ConfigParser.
> Glenn -- http://nevcal.com/
> A protocol is complete when there is nothing left to remove.
> -- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking
Follow the path of the Iguana...
More information about the Python-list