w3resource

NumPy Input and Output: DataSource() function

numpy.DataSource() function

DataSources can be local files or remote files/URLs. The files may also be compressed or uncompressed.

Syntax:

class numpy.DataSource(destpath='.')

Version: 1.15.0

Parameter:

Name Description Required /
Optional
destpath 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.
str or None
Optional

Notes:

URLs require a scheme string (http://) to be used, without it they will fail:

>>> repos = DataSource()
>>> repos.exists('www.google.com/index.html')
False
>>> repos.exists('http://www.google.com/index.html')
True

Temporary directories are deleted when the DataSource is deleted.

NumPy.DataSource() method Example:

>>> import numpy as np
>>> ds = np.DataSource('/home/guido')
>>> urlname = 'http://www.google.com/index.html'
>>> gfile = ds.open('http://www.google.com/index.html')  # remote file
>>> ds.abspath(urlname)

Output:

'C:\\home\\guido\\www.google.com\\index.html'

Python - NumPy Code Editor:

Previous: base_repr() function
Next: lib.format() function



Follow us on Facebook and Twitter for latest update.