Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #31727 > unrolled thread

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

Started bykampy <narasimha18sv@gmail.com>
First post2012-10-19 02:51 -0700
Last post2012-10-19 17:46 -0400
Articles 10 — 6 participants

Back to article view | Back to comp.lang.python


Contents

  section with in a section config file and reading that config file kampy <narasimha18sv@gmail.com> - 2012-10-19 02:51 -0700
    Re: section with in a section config file and reading that config file Tarek Ziadé <tarek@ziade.org> - 2012-10-19 12:09 +0200
      Re: section with in a section config file and reading that config file narasimha18sv@gmail.com - 2012-10-19 03:22 -0700
        Re: section with in a section config file and reading that config file Tarek Ziadé <tarek@ziade.org> - 2012-10-19 15:57 +0200
          Re: section with in a section config file and reading that config file rusi <rustompmody@gmail.com> - 2012-10-19 07:26 -0700
      Re: section with in a section config file and reading that config file narasimha18sv@gmail.com - 2012-10-19 03:22 -0700
      Re: section with in a section config file and reading that config file Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-19 21:29 +0000
        Re: section with in a section config file and reading that config file Tarek Ziadé <tarek@ziade.org> - 2012-10-19 23:59 +0200
          Re: section with in a section config file and reading that config file Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-19 22:59 +0000
    Re: section with in a section config file and reading that config file Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-10-19 17:46 -0400

#31727 — section with in a section config file and reading that config file

Fromkampy <narasimha18sv@gmail.com>
Date2012-10-19 02:51 -0700
Subjectsection with in a section config file and reading that config file
Message-ID<b5307867-0aa6-49db-b58d-803850a60d2d@googlegroups.com>
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

[toc] | [next] | [standalone]


#31729

FromTarek Ziadé <tarek@ziade.org>
Date2012-10-19 12:09 +0200
Message-ID<mailman.2502.1350641397.27098.python-list@python.org>
In reply to#31727
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

what you could do is have 2 files, and add a link from one to the other:


file1.ini:

   [AAA]
   extended = file2.ini

file2.ini:

   [BBB]
   a=1
   b=1

   [CCC]
   a=1
   b=2


then create a bit of logic on the top of ConfigParser to read back those 
values

HTH
Tarek

[toc] | [prev] | [next] | [standalone]


#31732

Fromnarasimha18sv@gmail.com
Date2012-10-19 03:22 -0700
Message-ID<f7b64b59-4871-4563-92c9-ccbf08a7ce47@googlegroups.com>
In reply to#31729
On Friday, 19 October 2012 15:39:57 UTC+5:30, 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
> 
> 
> 
> what you could do is have 2 files, and add a link from one to the other:
> 
> 
> 
> 
> 
> file1.ini:
> 
> 
> 
>    [AAA]
> 
>    extended = file2.ini
> 
> 
> 
> file2.ini:
> 
> 
> 
>    [BBB]
> 
>    a=1
> 
>    b=1
> 
> 
> 
>    [CCC]
> 
>    a=1
> 
>    b=2
> 
> 
> 
> 
> 
> then create a bit of logic on the top of ConfigParser to read back those 
> 
> values
> 
> 
> 
> HTH
> 
> Tarek

yes but it is not only for one structure like above there will be many sections like that

[toc] | [prev] | [next] | [standalone]


#31743

FromTarek Ziadé <tarek@ziade.org>
Date2012-10-19 15:57 +0200
Message-ID<mailman.2507.1350655080.27098.python-list@python.org>
In reply to#31732
On 10/19/12 12:22 PM, narasimha18sv@gmail.com wrote:
>
> yes but it is not only for one structure like above there will be many sections like that
I'd use yaml or json then...

[toc] | [prev] | [next] | [standalone]


#31749

Fromrusi <rustompmody@gmail.com>
Date2012-10-19 07:26 -0700
Message-ID<565d9f3e-f28f-4fe0-b1dc-53c7d765b8cf@rj6g2000pbc.googlegroups.com>
In reply to#31743
On Oct 19, 6:58 pm, Tarek Ziadé <ta...@ziade.org> wrote:
> On 10/19/12 12:22 PM, narasimha1...@gmail.com wrote:
>
> > yes but it is not only for one structure like above there will be many sections like that
>
> I'd use yaml or json then...

Maybe http://www.voidspace.org.uk/python/configobj.html ??

[toc] | [prev] | [next] | [standalone]


#31733

Fromnarasimha18sv@gmail.com
Date2012-10-19 03:22 -0700
Message-ID<mailman.2504.1350642167.27098.python-list@python.org>
In reply to#31729
On Friday, 19 October 2012 15:39:57 UTC+5:30, 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
> 
> 
> 
> what you could do is have 2 files, and add a link from one to the other:
> 
> 
> 
> 
> 
> file1.ini:
> 
> 
> 
>    [AAA]
> 
>    extended = file2.ini
> 
> 
> 
> file2.ini:
> 
> 
> 
>    [BBB]
> 
>    a=1
> 
>    b=1
> 
> 
> 
>    [CCC]
> 
>    a=1
> 
>    b=2
> 
> 
> 
> 
> 
> then create a bit of logic on the top of ConfigParser to read back those 
> 
> values
> 
> 
> 
> HTH
> 
> Tarek

yes but it is not only for one structure like above there will be many sections like that

[toc] | [prev] | [next] | [standalone]


#31769

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2012-10-19 21:29 +0000
Message-ID<5081c620$0$30003$c3e8da3$5496439d@news.astraweb.com>
In reply to#31729
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

[toc] | [prev] | [next] | [standalone]


#31774

FromTarek Ziadé <tarek@ziade.org>
Date2012-10-19 23:59 +0200
Message-ID<mailman.2537.1350683947.27098.python-list@python.org>
In reply to#31769
On 10/19/12 11:29 PM, Steven D'Aprano wrote:
> 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.
uh ?
>
> A configuration file is a file containing configuration data. That is all.
yeah,
organized in [sections]. a flat list of sections.

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

That's not an ini file anymore. That's a Foord-file :)

There's no notion of nested sections in ini configuration files, since 
there's no syntax marker to do the nesting

see https://en.wikipedia.org/wiki/INI_file#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.
This is not a ini configuration file anymore, since it introduces ad-hoc 
markers added that
are not recognized by other parsers.

Which is fine.

But instead of using an exotic, ad-hoc, look-alike ini file,
I strongly recommend using a standard that has native nested elements 
(json or yaml)

Cheers
Tarek

[toc] | [prev] | [next] | [standalone]


#31782

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2012-10-19 22:59 +0000
Message-ID<5081db43$0$30003$c3e8da3$5496439d@news.astraweb.com>
In reply to#31774
On Fri, 19 Oct 2012 23:59:03 +0200, Tarek Ziadé wrote:

> On 10/19/12 11:29 PM, Steven D'Aprano wrote:
>> 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.

> uh ?

"That is incorrect" means that your statement was wrong. Configuration 
files are NOT flat sequences of sections. *Some* configuration files are 
flat sequences of sections, some are nested, hierarchical sections, and 
some do not have sections at all.


>> A configuration file is a file containing configuration data. That is
>> all.
> yeah,
> organized in [sections]. a flat list of sections.

No, you are making the same wrong statement.

I have hundreds of configuration files on my computer, and very few of 
them are a flat list of sections.


>> "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.
> 
> That's not an ini file anymore. That's a Foord-file :)

Who cares? Did the poster say that he needed an INI file? No he did not. 
He says he needs a configuration file, and that is *much* more general 
than just INI files. Not all configuration files are INI files.

The poster says he needs a list of key:value pairs split into nested 
sections. Who cares if that is an INI file or not? It is still a 
configuration file, and he can have such a file if he wants.

You might as well complain that his sample config was not valid Python 
code. Who cares if it is not valid Python code, he didn't ask for valid 
Python code, and he didn't ask for a valid INI file.


-- 
Steven

[toc] | [prev] | [next] | [standalone]


#31773

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2012-10-19 17:46 -0400
Message-ID<mailman.2536.1350683236.27098.python-list@python.org>
In reply to#31727
On Fri, 19 Oct 2012 02:51:13 -0700 (PDT), kampy
<narasimha18sv@gmail.com> declaimed the following in
gmane.comp.python.general:

> 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

INI file structure (which I believe the config file follows) does not
support hierarchical sections. What you CAN do is something like:

[TopLevels]
topsections=AAA, DDD

[AAA]
sections=BBB, CCC

[BBB]
a=1
b=1

[CCC]
a=1
b=2

[DDD]
sections=EEE

[EEE]
a=3
b=4

	In other words, YOU have to define the nesting hierarchy by
specifying keys that identify the sections in the next level down.

-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
        wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web