我尝试使用 Python 的ConfigParser模块来保存设置。对于我的应用程序,保留部分中每个名称的大小写非常重要。文档提到将 str() 传递给ConfigParser.optionxform()可以完成此操作,但它对我不起作用。名字都是小写的。我错过了什么吗?
<~/.myrc contents>
[rules]
Monkey = foo
Ferret = baz
我得到的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')]