get_pkg_data_fileobjs#

astropy.utils.data.get_pkg_data_fileobjs(datadir, package=None, pattern='*', encoding=None)[源代码]#

返回给定目录中与给定glob模式匹配的所有数据文件的可读文件对象。

参数:
datadir : strPython :字符串

所需数据文件的名称/位置。以下之一:

  • 源分发中包含的目录的名称。路径与调用此函数的模块相关。例如,如果从 astropy.pkname 使用 'data' 把文件拿进来 astropy/pkgname/data

  • 当前不支持远程URL

package : str ,可选Python:字符串,可选

如果指定,则查找相对于给定包的文件,而不是默认的相对于调用模块的包查找的文件。

pattern : str ,可选Python:字符串,可选

与文件匹配的UNIX样式的文件名glob模式。见 glob 模块,以获取更多信息。默认情况下,匹配所有文件。

encoding : str ,可选Python:字符串,可选

When None (default), returns a file-like object with a read method that returns str (unicode) objects, using locale.getpreferredencoding as an encoding. This matches the default behavior of the built-in open when no mode argument is provided.

什么时候? 'binary' ,返回一个类似文件的对象,其中 read 方法返回 bytes 物体。

When another string, it is the name of an encoding, and the file-like object's read method will return str (unicode) objects, decoded from binary using the given encoding.

返回:
fileobjs : iteratorfile object objectPYTHON:PYTHON的迭代器:文件对象对象

中本地文件系统上每个文件的文件对象 数据中心 匹配 模式 .

实例

这将检索 astropy.wcs 测验::

>>> from astropy.utils.data import get_pkg_data_filenames
>>> for fd in get_pkg_data_fileobjs('data/maps', 'astropy.wcs.tests',
...                                 '*.hdr'):
...     fcontents = fd.read()
...