python3.1 configparser Konfigurationsdatei casesensitiv

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
torres
User
Beiträge: 47
Registriert: Samstag 29. Januar 2011, 13:23

Hallo,

habe eben das gleiche Problem gehabt wie in http://www.python-forum.de/viewtopic.ph ... ems#p72585 beschrieben: (von 2007)

Es geht darum, dass der configparser per default die Optionen case insensitiv ausgibt und im Beitrag ist auch ein workaround drin,
der mit meinem python3.1 leider nicht funktioniert.
Allerdings sehe ich in der Doku: http://docs.python.org/release/3.1/libr ... arser.html die Option
RawConfigParser.optionxform(option) beschrieben:
"RawConfigParser.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."

Und so funktioniert das dann auch:

Code: Alles auswählen

import configparser
config = configparser.RawConfigParser()
config.optionxform = str
config.read(config_file)
(..)
Wollte ich nur mitteilen, falls das noch jemand mal sucht.

Viele Gruesse,
Torres
Antworten