python-configParserがプロファイルを読み込むことについて、optionsは小文字の解決策になり、クラスの書き換え??

1171 ワード

configParserがプロファイルを読み込むことについて、optionsは小文字の解決策になります:解決策:第1の解決法案はソースコードを変更して、直接def optionxform()関数の中で'.lower()'削除:def optionxform(self,optionstr):return optionstrこのソリューションの不足点は、本機でしか有効ではなく、機械を交換すると問題が発生することです.2つ目の解決策は、自分でMyConfigParserを書き、ConfigParserから継承し、optionxform()メソッドを書き換えることです.次のようにします.
coding=utf-8
import ConfigParser
class MyConfigParser(ConfigParser.ConfigParser): def init(self, defaults=None): ConfigParser.ConfigParser.init(self, defaults=defaults)
def optionxform(self, optionstr):
    return optionstr

従来のoptionxform関数は、def optionxform(self,optionstr):return optionstr.lower()#を小文字に変換
クラスの継承、フォーマットは以下の通り:class father():def function(self,x):function 1 def function 1(self,x):function 2.......class child(father):passはクラスの継承の言い方に従って、上述は直接でよい:class MyConfigParser(ConfigParser.configParser):def optionxform(self,optionstr):return optionstrなぜこの一挙に多くの:def init(self,defaults=None):ConfigParser.ConfigParser.init(self, defaults=defaults)
クラスによると、initはサブクラスが定義されている場合は直接サブクラスを呼び出し、サブクラスが定義されていない場合はデフォルトで親クラスを呼び出すが、ここではなぜ何度も一挙に行うのだろうか.私はこの文を削除して、プロファイルを読み込んでも何の間違いも見つかりませんでした.何か隠したエラーが見つかりませんでしたか.