当前位置: 首页>>代码示例>>Python>>正文


Python ConfigParser.filename方法代码示例

本文整理汇总了Python中ConfigParser.ConfigParser.filename方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigParser.filename方法的具体用法?Python ConfigParser.filename怎么用?Python ConfigParser.filename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ConfigParser.ConfigParser的用法示例。


在下文中一共展示了ConfigParser.filename方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: load_configparser

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import filename [as 别名]
def load_configparser(config_file=None):
    cp = CP()
    if config_file is not None:
        config_file = resolve_file(config_file)
        if not os.path.isfile(config_file):
            es = "Could not find configuration file [%s]"
            raise ValueError(es % (config_file))
    else:
        possible_config_files = ['zdstackrc', 'zdstack.ini',
                                 '~/.zdstackrc', '~/.zdstack.ini',
                                 '~/.zdstack/zdstackrc',
                                 '~/.zdstack/zdstack.ini',
                                 '/etc/zdstackrc', '/etc/zdstack.ini',
                                 '/etc/zdstack/zdstackrc'
                                 '/etc/zdstack/zdstack.ini']
        possible_config_files = \
                        [resolve_file(x) for x in possible_config_files]
        if not [y for y in possible_config_files if os.path.isfile(y)]:
            raise ValueError("Could not find a valid configuration file")
        config_file = possible_config_files[0]
    config_fobj = StringIO(read_file(config_file))
    regexp = r'^\[(.*)\]%'
    sections = []
    for line in config_fobj.getvalue().splitlines():
        if re.match(regexp, line) and line in sections:
            es = "Duplicate section found in config: [%s]"
            raise ValueError(es % (line))
    config_fobj.seek(0)
    cp.readfp(config_fobj)
    cp.filename = config_file
    for section in cp.sections():
        cp.set(section, 'name', section)
    return cp
开发者ID:camgunz,项目名称:zdstack,代码行数:35,代码来源:__init__.py

示例2: load_app

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import filename [as 别名]
def load_app(filename):
    filename = os.path.abspath(filename)
    parser = ConfigParser()
    parser.read([filename])
    parser.filename = filename
    parser.defaults()['here'] = os.path.dirname(filename)
    parser.defaults()['__file__'] = filename
    return load_app_from_parser(parser)
开发者ID:iitwebdev,项目名称:lectures,代码行数:10,代码来源:loadapp.py


注:本文中的ConfigParser.ConfigParser.filename方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。