[Tutor] Problems with ConfigParser

Tony Cappellini tony at tcapp.com
Sun Apr 25 00:34:07 EDT 2004


I'm using the ConfigParser for the first time.
While it does seem to work- that is I can set the options in the section
to the value that I want,

when the ini file is written back out, the case of  the option text is
forced
to lower case (as opposed to the natural case of the text as it was read
in) and the Sections are in a very unusual order

Here is a snippet of what the orginal file looks like

[GPIB0]
AUTOPOLL=Yes
BoardName=PCI-GPIB
BoardType=0x5B
CICPROT=No
CompatibleType=0xFF
EOSchar=0
EOScmp=7-bit
EOSrd=No
EOSwrt=No
EOT=Yes
HSCableLength=Off
IPAddress=xxx.xxx.xxx.xxx
PAD=22
PPollTime=Default
SAD=None
SC=Yes
SerialNumber=0x010823C3
SRE=NO
TIMING=500nsec
TMO=10sec

[GPIB1]
AUTOPOLL=Yes
BoardName=None
BoardType=0xFF
CICPROT=No
CompatibleType=0xFF
EOSchar=0
EOScmp=7-bit
EOSrd=No
EOSwrt=No
EOT=Yes
HSCableLength=Off
IPAddress=xxx.xxx.xxx.xxx
PAD=0
PPollTime=Default
SAD=None
SC=Yes
SerialNumber=0xFFFFFFFF
SRE=No
TIMING=500nsec
TMO=10sec


Here is what is written out by the ConfigParser


[GPIB0]
eosrd = No
boardtype = 0x5B
compatibletype = 0xFF
hscablelength = Off
cicprot = No
serialnumber = 0x010823C3
eoschar = 0
ppolltime = Default
boardname = PCI-GPIB
sre = NO
sc = off
autopoll = Yes
pad = 22
eot = Yes
timing = 500nsec
eoswrt = No
sad = None
ipaddress = xxx.xxx.xxx.xxx
tmo = 10sec
eoscmp = 7-bit

[GPIB3]
eosrd = No
boardtype = 0xFF
compatibletype = 0xFF
hscablelength = Off
cicprot = No
serialnumber = 0xFFFFFFFF
eoschar = 0
ppolltime = Default
boardname = None
sre = No
sc = Yes
autopoll = Yes
pad = 0
eot = Yes
timing = 500nsec
eoswrt = No
sad = None
ipaddress = xxx.xxx.xxx.xxx
tmo = 10sec
eoscmp = 7-bit

Note - these two sections are sequential in the output file, but are not
in the same order as the original file.

While the program that needs to read this can still read the file, after
the COnfigParser has done it's mangling, I would very much prefer to keep
the file looking like the original.

If there is no built-in way to do this (pasing some kind of arg, or
setting a flag) I'll just throw away the config parser and do it myself.


The optionsform method talks about the case of the text- but it's pretty
confuing the way it's written.

Has anyone else seen this behaviour with ConfigParser ?




More information about the Tutor mailing list