擅长:python、mysql、java
<p>不幸的是,如果您想采用这种方法,就必须再次解析配置文件。您可以通过<code>main</code>中的<code>config_file = global_config['__file__']</code>获取该文件,并使用stdlib<code>ConfigParser</code>自己解析它。在</p>
<p>如果您喜欢这种包含单独部分的INI格式,那么Mozilla服务有一个很好的小模块,可以用来为您处理所有这些。它进行值转换(尝试将值转换为整数或布尔值)。它支持用其他部分扩展配置,例如<code>[foo:bar] key = value</code>,解析后将返回一个包含<code>settings['foo.bar.key'] == value</code>的简单字典。你也可以很方便地分析它的主要内容:</p>
<pre><code>def main(global_config, **settings):
config = get_configurator(global_config, **settings)
settings = config.registry.settings
# ... do your app configuration
return config.make_wsgi_app()
</code></pre>
<p><a href="https://wiki.mozilla.org/index.php?title=Services/Sync/Server/GlobalConfFile" rel="nofollow">https://wiki.mozilla.org/index.php?title=Services/Sync/Server/GlobalConfFile</a>
<a href="https://github.com/mozilla-services/mozservices/blob/master/mozsvc/config.py" rel="nofollow">https://github.com/mozilla-services/mozservices/blob/master/mozsvc/config.py</a></p>