section with in a section config file and reading that config file

Steven D'Aprano steve+comp.lang.python at pearwood.info
Fri Oct 19 17:29:04 EDT 2012


On Fri, 19 Oct 2012 12:09:53 +0200, Tarek Ziadé wrote:

> On 10/19/12 11:51 AM, kampy wrote:
>> hi all,
>> my requirement is to have section with in a section in config
>> parameters ex:
>> [AAA]
>>      [BBB]
>>       a=1
>>       b=1
>>      [CCC]
>>       a=1
>>       b=2
>> Any one help me in  understanding how to make sure that config file to
>> have a structure like this and reading with the config parser
>
> a configuration file is a flat sequences of sections, you cannot do this

That is incorrect.

A configuration file is a file containing configuration data. That is all.

"Configuration file" says nothing about the format of the file. It could 
be a Unix .rc file, a Windows .ini file with no section header, a 
Windows .ini file with section headers, a Python source code file, YAML, 
JSON, XML, a PLIST file, or any other format you decide to use.

If the Original Poster wants an ini file with nested sections, he can 
have an ini file with nested sections.

There is no support for nested sections in the ConfigParser module, but 
the ConfigObj third-party module supports it. Otherwise the OP could 
write his own code, possibly by subclassing from ConfigParser.

A simple google for "python ini file nested sections" finds this:

http://wiki.python.org/moin/ConfigParserShootout



-- 
Steven



More information about the Python-list mailing list