get_pkg_data_fileobjs#
- astropy.utils.data.get_pkg_data_fileobjs(datadir, package=None, pattern='*', encoding=None)[source]#
 Returns readable file objects for all of the data files in a given directory that match a given glob pattern.
- Parameters:
 - datadir
python:str Name/location of the desired data files. One of the following:
The name of a directory included in the source distribution. The path is relative to the module calling this function. For example, if calling from
astropy.pkname, use'data'to get the files inastropy/pkgname/dataRemote URLs are not currently supported
- package
python:str, optional If specified, look for a file relative to the given package, rather than the default of looking relative to the calling module’s package.
- pattern
python:str, optional A UNIX-style filename glob pattern to match files. See the
globmodule in the standard library for more information. By default, matches all files.- encoding
python:str, optional When
None(default), returns a file-like object with areadmethod that returnsstr(unicode) objects, usinglocale.getpreferredencodingas an encoding. This matches the default behavior of the built-inopenwhen nomodeargument is provided.When
'binary', returns a file-like object where itsreadmethod returnsbytesobjects.When another string, it is the name of an encoding, and the file-like object’s
readmethod will returnstr(unicode) objects, decoded from binary using the given encoding.
- datadir
 - Returns:
 - fileobjspython:iterator of python:file object 
object File objects for each of the files on the local filesystem in datadir matching pattern.
- fileobjspython:iterator of python:file object 
 
Examples
This will retrieve the contents of the data file for the
astropy.wcstests:>>> 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() ...