Retrieves a data file from the standard locations for the package and provides the file as a file-like object that reads bytes.
Parameters: | data_name : str
encoding : str, optional
cache : bool
|
---|---|
Returns: | fileobj : file-like
|
Raises: | urllib2.URLError, urllib.error.URLError
IOError
|
See also
Examples
This will retrieve a data file and its contents for the astropy.wcs tests:
from astropy.utils.data import get_pkg_data_fileobj
with get_pkg_data_fileobj('data/3d_cd.hdr') as fobj:
fcontents = fobj.read()
This would download a data file from the astropy data server because the standards/vega.fits file is not present in the source distribution. It will also save the file locally so the next time it is accessed it won’t need to be downloaded.:
from astropy.utils.data import get_pkg_data_fileobj
with get_pkg_data_fileobj('standards/vega.fits') as fobj:
fcontents = fobj.read()
This does the same thing but does not cache it locally:
with get_pkg_data_fileobj('standards/vega.fits', cache=False) as fobj:
fcontents = fobj.read()