|
From: Stef M. <S.M...@ru...> - 2007-09-26 14:37:39
|
hello,
Coming from windows/Delphi,
I've been using Python for half a year now.
For reading/writing windows ini-files,
I used ConfigParser (already much more difficult than Delphi ;-)
Now I needed an windows ini-file (not a registry file),
where the case of the keys was preserved
(ConfigParser makes all keys lowercase).
So someone advised me to use ConfigObj,
which should be superior to ConfigParser.
So I try to read the manual,
looks very nice and well written.
But when I read the introduction,
"*ConfigObj* is a simple but powerful config file reader and writer"
I miss the "simplicty".
Apparently this simplicity yields for a certain group of programmers,
probably coming from Linux / C,
certainly not for windows/Delphi programmers.
Now my problem is very-very simple,
but I don't get it done,
so maybe someone get give me a few simple ;-) hints.
I open an ini-file for reading:
ini = ConfigObj ( filename )
I want to see what sections are ther:
ini.sections
Now I want to see what keys are in 1 specific sections:
??????
things like
ini.values()
ini.items()
give me all kind of key-value pairs, but without knowing in which
section they are stored ??
thanks,
Stef Mientki
Het UMC St Radboud staat geregistreerd bij de Kamer van Koophandel in het handelsregister onder nummer 41055629.
The Radboud University Nijmegen Medical Centre is listed in the Commercial Register of the Chamber of Commerce under file number 41055629.
|
|
From: Michael F. <fuz...@vo...> - 2007-09-26 14:54:51
|
Stef Mientki wrote: > [snip..] > Now my problem is very-very simple, > but I don't get it done, > so maybe someone get give me a few simple ;-) hints. > > I open an ini-file for reading: > ini = ConfigObj ( filename ) > > > I want to see what sections are ther: > ini.sections > > Now I want to see what keys are in 1 specific sections: > ?????? > things like > ini.values() > ini.items() > ini.keys() or ini[section_name].keys() ConfigObj has a 'dictionary interface' - so all the methods available on a normal Python dictionary can be used with ConfigObj. Simple enough? HTH Michael http://www.manning.com/foord > give me all kind of key-value pairs, but without knowing in which > section they are stored ?? > > thanks, > Stef Mientki > > > > > > Het UMC St Radboud staat geregistreerd bij de Kamer van Koophandel in het handelsregister onder nummer 41055629. > The Radboud University Nijmegen Medical Centre is listed in the Commercial Register of the Chamber of Commerce under file number 41055629. > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2005. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Configobj-develop mailing list > Con...@li... > https://lists.sourceforge.net/lists/listinfo/configobj-develop > > |
|
From: Stef M. <s.m...@ru...> - 2007-09-26 21:30:17
|
Michael Foord wrote: > Stef Mientki wrote: > >> [snip..] >> Now my problem is very-very simple, >> but I don't get it done, >> so maybe someone get give me a few simple ;-) hints. >> >> I open an ini-file for reading: >> ini = ConfigObj ( filename ) >> >> >> I want to see what sections are ther: >> ini.sections >> >> Now I want to see what keys are in 1 specific sections: >> ?????? >> things like >> ini.values() >> ini.items() >> >> > > thanks Michael, > ini.keys() > but that gives me the section names, so it's the same as ini.sections > or > > ini[section_name].keys() > aha that's what I'm looking for. > ConfigObj has a 'dictionary interface' - so all the methods available on > a normal Python dictionary can be used with ConfigObj. > > Simple enough? > Yes that's indeed not too difficult ;-) the reason why I've so much trouble with this, is probably that I (almost) never use dictionaries. Still one other small question, which must be peanuts for you (and others), how do I read a value as a normal string ? When I've an inifile with following content: size = (134,433) ConfigObj gives me back a list ['(134', '433)'] Undoubtedly usefull in most cases (although the brackets look weird to me ;-), but as I move around and manipulate these "things" all over in my program, I just want to handle 1 type, for which I've chosen the string type. cheers, Stef |
|
From: Michael F. <fuz...@vo...> - 2007-09-26 21:38:28
|
Stef Mientki wrote: >> ini[section_name].keys() >> >> > aha that's what I'm looking for. > >> ConfigObj has a 'dictionary interface' - so all the methods available on >> a normal Python dictionary can be used with ConfigObj. >> >> Simple enough? >> >> > Yes that's indeed not too difficult ;-) > the reason why I've so much trouble with this, > is probably that I (almost) never use dictionaries. > Shock horror - Python is *built* on dictionaries! :-) > Still one other small question, which must be peanuts for you (and others), > how do I read a value as a normal string ? > When I've an inifile with following content: > size = (134,433) > ConfigObj gives me back a list > ['(134', '433)'] > By default ConfigObj treats comma separated values as lists. This *can* be inconvenient, so you can switch it off. ini = ConfigObj(filename, list_values=False) HTH Michael Foord http://www.manning.com/foord > Undoubtedly usefull in most cases (although the brackets look weird to > me ;-), > but as I move around and manipulate these "things" all over in my program, > I just want to handle 1 type, for which I've chosen the string type. > > cheers, > Stef > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2005. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Configobj-develop mailing list > Con...@li... > https://lists.sourceforge.net/lists/listinfo/configobj-develop > > |
|
From: Michael F. <fuz...@vo...> - 2007-09-26 22:34:28
|
Stef Mientki wrote: >> Shock horror - Python is *built* on dictionaries! :-) >> >> > Yes I read that before, > but doesn't mean that everyone is using them (explictly) ;-) > (I mainly do signal analysis and simulation) > >> >> >>> Still one other small question, which must be peanuts for you (and others), >>> how do I read a value as a normal string ? >>> When I've an inifile with following content: >>> size = (134,433) >>> ConfigObj gives me back a list >>> ['(134', '433)'] >>> >>> >>> >> By default ConfigObj treats comma separated values as lists. >> > Yes I read that ... > so I tried > ini.list_values = False > but that didn't work. > >> This *can* >> be inconvenient, so you can switch it off. >> >> >> ini = ConfigObj(filename, list_values=False) >> >> >> > Thanks that works ok. > So why doesn't > ini.list_values = False > this work ? > Because by then ConfigObj has *already* read the values in. Changing the settings afterwards only affects how they are written back out. Michael http://www.manning.com/foord > cheers, > Stef > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2005. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Configobj-develop mailing list > Con...@li... > https://lists.sourceforge.net/lists/listinfo/configobj-develop > > |
|
From: Michael F. <fuz...@vo...> - 2007-09-27 21:38:49
|
Stef Mientki wrote:
>>>>
>>>>
>>>>
>>> Thanks that works ok.
>>> So why doesn't
>>> ini.list_values = False
>>> this work ?
>>>
>>>
>>>
>> Because by then ConfigObj has *already* read the values in. Changing the
>> settings afterwards only affects how they are written back out.
>>
>>
>>
> Thanks Michael, that explains.
>
> Another question: is it possible to force the normal windows end-of-line
> (CR+LF),
> when writing to the config file ?
>
Hmmm... doesn't that happen automatically on Windows?
ConfigObj does expose a 'newlines' attribute ('\r\n', '\n', or '\r'). It
does however go to great lengths to preserve line endings in a config
file it has read - or to use the native ones for the platform.
Michael
http://www.manning.com/foord
> cheers,
> Stef
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2005.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Configobj-develop mailing list
> Con...@li...
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>
>
|
|
From: Stef M. <s.m...@ru...> - 2007-09-26 22:30:02
|
> Shock horror - Python is *built* on dictionaries! :-)
>
Yes I read that before,
but doesn't mean that everyone is using them (explictly) ;-)
(I mainly do signal analysis and simulation)
>
>> Still one other small question, which must be peanuts for you (and others),
>> how do I read a value as a normal string ?
>> When I've an inifile with following content:
>> size = (134,433)
>> ConfigObj gives me back a list
>> ['(134', '433)']
>>
>>
>
> By default ConfigObj treats comma separated values as lists.
Yes I read that ...
so I tried
ini.list_values = False
but that didn't work.
> This *can*
> be inconvenient, so you can switch it off.
>
>
> ini = ConfigObj(filename, list_values=False)
>
>
Thanks that works ok.
So why doesn't
ini.list_values = False
this work ?
cheers,
Stef
|
|
From: Stef M. <s.m...@ru...> - 2007-09-27 20:02:23
|
>>> >>> >> Thanks that works ok. >> So why doesn't >> ini.list_values = False >> this work ? >> >> > > Because by then ConfigObj has *already* read the values in. Changing the > settings afterwards only affects how they are written back out. > > Thanks Michael, that explains. Another question: is it possible to force the normal windows end-of-line (CR+LF), when writing to the config file ? cheers, Stef |
|
From: Stef M. <s.m...@ru...> - 2007-09-27 22:34:36
|
>> Another question: is it possible to force the normal windows end-of-line
>> (CR+LF),
>> when writing to the config file ?
>>
>>
>
> Hmmm... doesn't that happen automatically on Windows?
>
>
Hmm.. now you told me, it does indeed ???
So I guess my observation was caused by a crash or error somewhere in my
program.
> ConfigObj does expose a 'newlines' attribute ('\r\n', '\n', or '\r'). It
> does however go to great lengths to preserve line endings in a config
> file it has read - or to use the native ones for the platform.
>
>
Great component,
- my names in the name-value pairs keep their case
- the order of the items in a section is preserved
thanks very much Michael.
I'll let you know when I release my program ( a hardware / software
simulator for microcontrolers),
so you can add it to the " Real World" chapter.
cheers,
Stef
|
|
From: Michael F. <fuz...@vo...> - 2007-09-27 22:59:52
|
Stef Mientki wrote:
>>> Another question: is it possible to force the normal windows end-of-line
>>> (CR+LF),
>>> when writing to the config file ?
>>>
>>>
>>>
>> Hmmm... doesn't that happen automatically on Windows?
>>
>>
>>
> Hmm.. now you told me, it does indeed ???
> So I guess my observation was caused by a crash or error somewhere in my
> program.
>
>> ConfigObj does expose a 'newlines' attribute ('\r\n', '\n', or '\r'). It
>> does however go to great lengths to preserve line endings in a config
>> file it has read - or to use the native ones for the platform.
>>
>>
>>
> Great component,
> - my names in the name-value pairs keep their case
> - the order of the items in a section is preserved
>
> thanks very much Michael.
> I'll let you know when I release my program ( a hardware / software
> simulator for microcontrolers),
> so you can add it to the " Real World" chapter.
>
Cool - sounds great.
Michael
> cheers,
> Stef
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2005.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Configobj-develop mailing list
> Con...@li...
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>
>
|