相关疑难解决方法(0)

保留ConfigParser中的案例?

我曾尝试使用Python的ConfigParser模块来保存设置.对于我的应用程序,重要的是我在我的部分中保留每个名称的大小写.文档提到将str()传递给ConfigParser.optionxform()会实现这一点,但它对我不起作用.名称都是小写的.我错过了什么吗?

<~/.myrc contents>
[rules]
Monkey = foo
Ferret = baz
Run Code Online (Sandbox Code Playgroud)

我获得的Python伪代码:

import ConfigParser,os

def get_config():
   config = ConfigParser.ConfigParser()
   config.optionxform(str())
    try:
        config.read(os.path.expanduser('~/.myrc'))
        return config
    except Exception, e:
        log.error(e)

c = get_config()  
print c.options('rules')
[('monkey', 'foo'), ('ferret', 'baz')]
Run Code Online (Sandbox Code Playgroud)

python configuration-files python-2.x configparser

77
推荐指数
4
解决办法
3万
查看次数