python - python 解析器如何包含 "AT"文件(ini)

标签 python ini

[db_finding]
cluster_name  :  db_finding
connect_timeout_ms  :  900

[.@host]
ip  :  10.1.7.71
port  :  6500

[.@host]
ip  :  10.1.7.65
port  :  6500

我可以使用:

val = cf.get("db_finding",'cluster_name')

成功了。

但是我怎样才能获得“AT”主机呢?

最佳答案

有趣的问题..花了我一点时间。我喜欢它:D 现有的解决方案不是很强大。

import ConfigParser

class MultiOrderedDict(dict):
    def __setitem__(self, key, value):
        if key in self and isinstance(value, list):
            self[key].append(value[0])
            return

        super(MultiOrderedDict, self).__setitem__(key, value)

config = ConfigParser.ConfigParser(dict_type=MultiOrderedDict)
config.read(['cluster.conf'])
print config.items('.@host')
print config.get('.@host', 'ip').split('\n')

关于python - python 解析器如何包含 "AT"文件(ini),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33162286/

相关文章:

c - INI 库 : linked list (abstract) issue

java - 存储名称和值的最佳文件格式

php - 哪个更好 php.ini vs ini_set()

asp.net - ASP.NET Web 服务应用程序中 INI 文件的保存位置

python - 在Python中,为什么这一行从文件中运行(无异常),但在shell中运行时抛出异常?

python - 列 'django_migrations.id' 具有不受支持的类型 'serial' [使用 Amazon Redshift]

python - Django Celery 日志记录最佳实践

json - 使用 jq + bash 将 json 转换为 ini 文件

python - 从 pandas 系列对象获取值

python - 无法在Python中进行OpenCV的人脸检测