numpy.
DataSource
(destpath ='。' )[源代码] ¶通用数据源文件(文件,http,ftp等)。
数据源可以是本地文件或远程文件/ URL。文件也可以被压缩或解压缩。DataSource隐藏了下载文件的一些底层细节,使您可以简单地传递有效的文件路径(或URL)并获取文件对象。
下载源文件以供使用的目录的路径。如果destpath为None,将创建一个临时目录。默认路径是当前目录。
笔记
URL需要使用方案字符串(http://
),否则将失败:
>>> repos = np.DataSource()
>>> repos.exists('www.google.com/index.html')
False
>>> repos.exists('http://www.google.com/index.html')
True
删除数据源时,将删除临时目录。
例子
>>> 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'
方法
|
返回DataSource目录中文件的绝对路径。 |
|
测试路径是否存在。 |
|
打开并返回类似文件的对象。 |