本文简要介绍 python 语言中 numpy.DataSource
的用法。
用法:
class numpy.DataSource(destpath='.')
通用数据源文件(文件、http、ftp、...)。
DataSources可以是本地文件或远程文件/URL。文件也可以是压缩的或未压缩的。 DataSource隐藏了下载文件的一些低级细节,允许您简单地传入有效的文件路径(或URL)并获取文件对象。
- destpath: str 或无,可选
源文件下载到以供使用的目录的路径。如果 destpath 为 None,将创建一个临时目录。默认路径是当前目录。
参数:
注意:
URL 需要使用方案字符串(
http://
),没有它它们将失败:>>> repos = np.DataSource() >>> repos.exists('www.google.com/index.html') False >>> repos.exists('http://www.google.com/index.html') True
删除 DataSource 时,临时目录也会被删除。
例子:
>>> ds = np.DataSource('/home/guido') >>> urlname = 'http://www.google.com/' >>> gfile = ds.open('http://www.google.com/') >>> ds.abspath(urlname) '/home/guido/www.google.com/index.html' >>> ds = np.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/.../home/guido/foobar.txt'
相关用法
- Python numpy RandomState.standard_exponential用法及代码示例
- Python numpy hamming用法及代码示例
- Python numpy legendre.legint用法及代码示例
- Python numpy chararray.ndim用法及代码示例
- Python numpy chebyshev.chebsub用法及代码示例
- Python numpy chararray.nbytes用法及代码示例
- Python numpy ma.indices用法及代码示例
- Python numpy matrix.A1用法及代码示例
- Python numpy MaskedArray.var用法及代码示例
- Python numpy ma.zeros用法及代码示例
- Python numpy broadcast用法及代码示例
- Python numpy matrix.T用法及代码示例
- Python numpy matrix.I用法及代码示例
- Python numpy MaskedArray.T用法及代码示例
- Python numpy hermite.hermfromroots用法及代码示例
- Python numpy hermite_e.hermediv用法及代码示例
- Python numpy recarray.dot用法及代码示例
- Python numpy random.mtrand.RandomState.wald用法及代码示例
- Python numpy trim_zeros用法及代码示例
- Python numpy chebyshev.chebdiv用法及代码示例
- Python numpy linalg.svd用法及代码示例
- Python numpy copy用法及代码示例
- Python numpy negative用法及代码示例
- Python numpy ndarray.astype用法及代码示例
- Python numpy ma.diff用法及代码示例
注:本文由纯净天空筛选整理自numpy.org大神的英文原创作品 numpy.DataSource。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。