Hello I use ConfigParser as show below to read a config.txt file;
from ConfigParser import ConfigParser
config = ConfigParser()
config.read('co nfig.txt')
items = config.items('F V')
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_180 3: 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. 3 4354 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(opt ion)
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.optionxf orm = str
# ...
Or, to be on the safe side:
class MyCasePreservin gConfigParser(C onfigParser):
optionxform = str
config = MyCasePreservin gConfigParser()
# ...
Peter
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(opt ion)
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.optionxf orm = str
# ...
Or, to be on the safe side:
class MyCasePreservin gConfigParser(C onfigParser):
optionxform = str
config = MyCasePreservin gConfigParser()
# ...
Peter
Hi,
from the documentation:
optionxform(opt ion)
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 following code, I bind __read_ini to __read and override __read so it
can choose between __read_ini and __read_custom. But it seems that
__read_custom never gets called when I expect it to aways be called. I have
a feeling this has to do with me not...
|
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 *
class MyConfigParser(ConfigParser):
def __init__(self, defaults=None):
ConfigParser.__init__(self, defaults)
|
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 like the
following in a configuration file:
data_file=${HOME}/mydata.dat
....(where HOME=/home/matt) and have ConfigParser automatically expand
it to:
|
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 local directory to be backed up followed
# by the directory name on the FTP server.
#
# Example: /home/joe/digital photos = photos
|
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 Manlio Perillo
| |
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, I'd rather
use a syntax that ConfigParser can't handle.
I know I can maintain two separate configuration files, and if I have
to I will, but I'd rather avoid that, if possible, and a solution
that suits my purposes is quite straightforward. I...
|
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 ConfigParser
def whatzit(thingname, thing):
print thingname, "value:", thing
print thingname, "length:", len(thing)
|
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 = fahdata.FAHData()
self.INI = ConfigParser.ConfigParser()
if os.path.exists(config_file):
try:
self.INI.read(config_file)
|
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)
config.add_section('test')
config.set('test', 'haha', 'hehe')
|
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
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |