Simple ini Config parser examples needed

Chris Rebert clp at rebertia.com
Tue Dec 2 22:31:14 CET 2008


On Tue, Dec 2, 2008 at 1:18 PM, RON BRENNAN <rbrennan55 at hotmail.com> wrote:
> Hello,
>
> I have a very simple ini file that I needs parsed.  What is the best way I
> can parse an ini file that doesn't include sections?
>
> As in:
>
Since it appears that ConfigParser requires at least one section
header, I'll assume the file starts with the following line:

[main]
> person=tall
> height=small
> shoes=big
>
>
> Thats it.  Can anyone help me?

Completely untested:

import ConfigParser
config = ConfigParser.RawConfigParser()
config.readfp(open("path/to/file.cfg"))
config.get("main", "height") #==> "small"

Cheers,
Chris
-- 
Follow the path of the Iguana...
http://rebertia.com

>
> Thanks,
> Ron
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>



More information about the Python-list mailing list