473,325 Members | 2,671 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,325 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 4309
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
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.