astropy 5.0

ParametersRaisesReturns
get_pkg_data_contents(data_name, package=None, encoding=None, cache=True)

Parameters

data_name : str

Name/location of the desired data file. One of the following:

  • The name of a data file included in the source distribution. The path is relative to the module calling this function. For example, if calling from astropy.pkname , use 'data/file.dat' to get the file in astropy/pkgname/data/file.dat . Double-dots can be used to go up a level. In the same example, use '../data/file.dat' to get astropy/data/file.dat .

  • If a matching local file does not exist, the Astropy data server will be queried for the file.

  • A hash like that produced by compute_hash can be requested, prefixed by 'hash/' e.g. 'hash/34c33b3eb0d56eb9462003af249eff28'. The hash will first be searched for locally, and if not found, the Astropy data server will be queried.

  • A URL to some other file.

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

encoding : str, optional

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

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

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

cache : bool

If True, the file will be downloaded and saved locally or the already-cached local copy will be accessed. If False, the file-like object will directly access the resource (e.g. if a remote URL is accessed, an object like that from urllib.request.urlopen is returned).

Raises

urllib.error.URLError

If a remote file cannot be found.

OSError

If problems occur writing or reading a local file.

Returns

contents : bytes

The complete contents of the file as a bytes object.

Retrieves a data file from the standard locations and returns its contents as a bytes object.

See Also

get_pkg_data_filename

returns a local name for a file containing the data

get_pkg_data_fileobj

returns a file-like object with the data

Examples

See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /astropy/utils/data.py#661
type: <class 'function'>
Commit: