-
class numpy.DataSource(destpath='.')
[source] -
A generic data source file (file, http, ftp, ...).
DataSources can be local files or remote files/URLs. The files may also be compressed or uncompressed. DataSource hides some of the low-level details of downloading the file, allowing you to simply pass in a valid file path (or URL) and obtain a file object.
Parameters: destpath : str or None, optional
Path to the directory where the source file gets downloaded to for use. If
destpath
is None, a temporary directory will be created. The default path is the current directory.Notes
URLs require a scheme string (
http://
) to be used, without it they will fail:12345>>> repos
=
DataSource()
>>> repos.exists(
'www.google.com/index.html'
)
False
True
Temporary directories are deleted when the DataSource is deleted.
Examples
1234567891011>>> ds
=
DataSource(
'/home/guido'
)
>>> ds.abspath(urlname)
'/home/guido/www.google.com/site/index.html'
>>> ds
=
DataSource(
None
)
# use with temporary file
>>> ds.
open
(
'/home/guido/foobar.txt'
)
<
open
file
'/home/guido.foobar.txt'
, mode
'r'
at
0x91d4430
>
>>> ds.abspath(
'/home/guido/foobar.txt'
)
'/tmp/tmpy4pgsP/home/guido/foobar.txt'
Methods
abspath
(path)Return absolute path of file in the DataSource directory. exists
(path)Test if path exists. open
(path[, mode])Open and return file-like object.
numpy.DataSource()

2025-01-10 15:47:30
Please login to continue.