astro py:docs

- Index
- Modules

### Navigation

- next »
- « previous |
- Astropy v0.3 »
- Astropy Core Package Utilities (`astropy.utils`) »
- get_pkg_data_fileobjs

# get_pkg_data_fileobjs

`astropy.utils.data.``get_pkg_data_fileobjs`(datadir, pattern=u'*', encoding=None)

  Returns readable file objects for all of the data files in a given directory that match a given glob pattern.

  Parameters:

  datadir : 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 in `astropy/pkgname/data`
  > > - Remote URLs are not currently supported

  pattern : str, optional

  > A UNIX-style filename glob pattern to match files. See the `glob` module in the standard library for more information. By default, matches all files.

  encoding : str, optional

  > When `None` (default), returns a file-like object with a `read` method that on Python 2.x returns `bytes` objects and on Python 3.x 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.

  > When `'binary'`, returns a file-like object where its `read` method returns `bytes` objects.

  > 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.

  Returns:

  fileobjs : iterator of file objects

  > File objects for each of the files on the local filesystem in datadir matching pattern.

  Examples

  This will retrieve the contents of the data file for the `astropy.wcs` tests:

      from astropy.utils.data import get_pkg_data_filenames

      for fd in get_pkg_data_filename('maps', '*.hdr'):
          fcontents = fd.read()