468,305 Members | 1,510 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,305 developers. It's quick & easy.

Help with ConfigParser

Hello I use ConfigParser as show below to read a config.txt file;

from ConfigParser import ConfigParser

config = ConfigParser()
config.read('config.txt')
items = config.items('FV')
for item in items:
module_name = item[0]
print module_name
The config.txt file has the following

[FV]
# Set the module to "1" to enable the regression test run on it, otherwise
set it to "0"

ip_dtlmmio0_1803: 0
ip_gpio0_4004: 0
ip_dmac0_1903: 0
ip_ptA_a_sdramc_2022: 1
ip_timer0_3012: 0

the output has been convert to lowercase, i.e ip_ptA_a_sdramc_2022 become
ip_pta_a_sdramc_2022
(the captial letter 'A, become lower case 'a').

Question: How can I pervent ConfigParse to convert Upper case yo lower
case??, thanks.

Oct 2 '06 #1
3 4068
to*****@philips.com wrote:
Question: How can I pervent ConfigParse to convert Upper case yo lower
case??, thanks.
http://docs.python.org/dev/lib/RawCo...r-objects.html

"""
optionxform(option)

Transforms the option name option as found in an input file or as passed in
by client code to the form that should be used in the internal structures.
The default implementation returns a lower-case version of option;
subclasses may override this or client code can set an attribute of this
name on instances to affect this behavior. Setting this to str(), for
example, would make option names case sensitive.
""""

If you don't pass defaults:

config = ConfigParser()
config.optionxform = str
# ...

Or, to be on the safe side:

class MyCasePreservingConfigParser(ConfigParser):
optionxform = str

config = MyCasePreservingConfigParser()
# ...

Peter
Oct 2 '06 #2
Hello Peter,

Thanks for your help, and it works now!

Tony.

Peter Otten wrote:
to*****@philips.com wrote:
Question: How can I pervent ConfigParse to convert Upper case yo lower
case??, thanks.

http://docs.python.org/dev/lib/RawCo...r-objects.html

"""
optionxform(option)

Transforms the option name option as found in an input file or as passed in
by client code to the form that should be used in the internal structures.
The default implementation returns a lower-case version of option;
subclasses may override this or client code can set an attribute of this
name on instances to affect this behavior. Setting this to str(), for
example, would make option names case sensitive.
""""

If you don't pass defaults:

config = ConfigParser()
config.optionxform = str
# ...

Or, to be on the safe side:

class MyCasePreservingConfigParser(ConfigParser):
optionxform = str

config = MyCasePreservingConfigParser()
# ...

Peter
Oct 2 '06 #3
Hi,
from the documentation:

optionxform(option)

Transforms the option name option as found in an input file or as passed in
by client code to the form that should be used in the internal structures.
The default implementation returns a lower-case version of option;
subclasses may override this or client code can set an attribute of this
name on instances to affect this behavior. Setting this to str(), for
example, would make option names case sensitive.

Bye,
Enrico
Oct 2 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Greg Krohn | last post: by
2 posts views Thread by Roy H. Berger | last post: by
6 posts views Thread by Matthew Barnes | last post: by
3 posts views Thread by Stephen Boulet | last post: by
11 posts views Thread by Manlio Perillo | last post: by
2 posts views Thread by rzed | last post: by
10 posts views Thread by Terry Carroll | last post: by
1 post views Thread by pipehappy | last post: by
4 posts views Thread by Phoe6 | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.