473,387 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 4312
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Greg Krohn | last post by:
I'm trying to subclass ConfigParser so I can use a custom __read method (the custom format doesn't conform to RFC 822) when needed. Needless to say, it's not working as expected. In the...
2
by: Roy H. Berger | last post by:
If I want to subclass ConfigParser and changed the optionxform method to not return things in lower case wouldn't I just need the following code in my subclasss module? from ConfigParser import...
6
by: Matthew Barnes | last post by:
I'm considering submitting a patch for Python 2.4 to allow environment variable expansion in ConfigParser files. The use cases for this should be obvious. I'd like to be able to specify something...
3
by: Stephen Boulet | last post by:
I'm having a bit of trouble getting my head around the ConfigParser module. I have a very simple configuration file; maybe the easiest thing to do would be to show that: ============ # Add a...
11
by: Manlio Perillo | last post by:
Regards. Since sections in CongiParser files are delimited by , why there is not an escape (and unescape) function for escaping &, characters to &, [ and ] ? Thanks ...
2
by: rzed | last post by:
I am working with PythonCard in one of my apps. For its purposes, it uses an .ini file that is passed to ConfigParser. For my app, I also need configuration information, but for various reasons,...
10
by: Terry Carroll | last post by:
It looks like ConfigParser will accept a list to be writing to the *.ini file; but when reading it back in, it treats it as a string. Example: ############################### import...
5
by: mwt | last post by:
Hi - I'm having a little trouble using exceptions properly. I currently have an initialization function on a little app that looks like this: def __init__(self, config_file): self.fahdata =...
1
by: pipehappy | last post by:
Hello everyone: I came across the module ConfigParser and can use it correctly. import ConfigParser fp = open('test.cfg','w+') config = ConfigParser.ConfigParser() config.readfp(fp)...
4
by: Phoe6 | last post by:
Hi, I have a configfile, in fact, I am providing a configfile in the format: Name: Foo Author: Bar Testcases: tct123
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.