__init__.py 文件源码

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

项目:minihydra 作者: VillanCh 项目源码 文件源码
def read(self, filenames, encoding=None):
        """Read and parse a filename or a list of filenames.

        Files that cannot be opened are silently ignored; this is
        designed so that you can specify a list of potential
        configuration file locations (e.g. current directory, user's
        home directory, systemwide directory), and all existing
        configuration files in the list will be read.  A single
        filename may also be given.

        Return list of successfully read files.
        """
        if PY2 and isinstance(filenames, bytes):
            # we allow for a little unholy magic for Python 2 so that
            # people not using unicode_literals can still use the library
            # conveniently
            warnings.warn(
                "You passed a bytestring as `filenames`. This will not work"
                " on Python 3. Use `cp.read_file()` or switch to using Unicode"
                " strings across the board.",
                DeprecationWarning,
                stacklevel=2,
            )
            filenames = [filenames]
        elif isinstance(filenames, str):
            filenames = [filenames]
        read_ok = []
        for filename in filenames:
            try:
                with open(filename, encoding=encoding) as fp:
                    self._read(fp, filename)
            except IOError:
                continue
            read_ok.append(filename)
        return read_ok
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号