config.py 文件源码

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

项目:onefl-deduper 作者: ufbmi 项目源码 文件源码
def from_pyfile(self, filename, silent=False):
        """Updates the values in the config from a Python file.

        :param filename: the filename of the config.  This can either be an
                         absolute filename or a filename relative to the
                         root path.
        :param silent: set to ``True`` if you want silent failure for missing
                       files.

        """
        filename = os.path.join(self.root_path, filename)
        d = types.ModuleType('config')
        d.__file__ = filename
        try:
            with open(filename) as config_file:
                exec(compile(config_file.read(), filename, 'exec'), d.__dict__)
        except IOError as e:
            if silent and e.errno in (errno.ENOENT, errno.EISDIR):
                return False
            e.strerror = 'Unable to load configuration file (%s)' % e.strerror
            raise
        self.from_object(d)
        return True
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号