astropy 5.0

NotesParametersReturnsBackRef
get_readable_fileobj(name_or_obj, encoding=None, cache=False, show_progress=True, remote_timeout=None, sources=None, http_headers=None)

This supports passing filenames, URLs, and readable file-like objects, any of which can be compressed in gzip, bzip2 or lzma (xz) if the appropriate compression libraries are provided by the Python installation.

Notes

This function is a context manager, and should be used for example as:

with get_readable_fileobj('file.dat') as f:
    contents = f.read()

If a URL is provided and the cache is in use, the provided URL will be the name used in the cache. The contents may already be stored in the cache under this URL provided, they may be downloaded from this URL, or they may be downloaded from one of the locations listed in sources . See :None:None:`~download_file` for details.

Parameters

name_or_obj : str or file-like

The filename of the file to access (if given as a string), or the file-like object to access.

If a file-like object, it must be opened in binary mode.

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 or "update", optional

Whether to cache the contents of remote URLs. If "update", check the remote URL for a new version but store the result in the cache.

show_progress : bool, optional

Whether to display a progress bar if the file is downloaded from a remote server. Default is :None:None:`True`.

remote_timeout : float

Timeout for remote requests in seconds (default is the configurable :None:None:`astropy.utils.data.Conf.remote_timeout`).

sources : list of str, optional

If provided, a list of URLs to try to obtain the file from. The result will be stored under the original URL. The original URL will not be tried unless it is in this list; this is to prevent long waits for a primary server that is known to be inaccessible at the moment.

http_headers : dict or None

HTTP request headers to pass into urlopen if needed. (These headers are ignored if the protocol for the name_or_obj / sources entry is not a remote HTTP URL.) In the default case (None), the headers are User-Agent: some_value and Accept: */* , where some_value is set by astropy.utils.data.conf.default_http_user_agent .

Returns

file : readable file-like

Yield a readable, seekable file-like object from a file or URL.

Examples

See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

astropy.utils.data.get_file_contents

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#166
type: <class 'function'>
Commit: