config_files.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:artemis 作者: QUVA-Lab 项目源码 文件源码
def _get_config_object(config_path, use_cashed_config=True):
    '''
    Returns a ConfigParser for the config file at the given path. If no file exists, an empty config file is created.
    :param config_path:
    :param use_cashed_config: If set to True, will return the previously created ConfigParser file (if previously created).
        If set to False, will re-read the config file from disk. If a ConfigParser was previously created, it will not be replaced!
    :return:
    '''
    if config_path not in _CONFIG_OBJECTS or not use_cashed_config:
        config = ConfigParser()
        if not os.path.exists(config_path):
            with open(config_path,'w') as f:
                config.write(f)
        else:
            config.read(config_path)
        if use_cashed_config:
            _CONFIG_OBJECTS[config_path] = config
    else:
        config = _CONFIG_OBJECTS[config_path]
    return config
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号