Movatterモバイル変換


[0]ホーム

URL:


SciPy

numpy.DataSource

classnumpy.DataSource(destpath='.')[source]

A generic data source file (file, http, ftp, …).

DataSources can be local files or remote files/URLs. The files mayalso be compressed or uncompressed. DataSource hides some of thelow-level details of downloading the file, allowing you to simply passin 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 foruse. Ifdestpath 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 theywill 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.

Examples

>>>ds=DataSource('/home/guido')>>>urlname='http://www.google.com/index.html'>>>gfile=ds.open('http://www.google.com/index.html')# remote file>>>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, encoding, newline])Open and return file-like object.

Previous topic

numpy.base_repr

Next topic

numpy.DataSource.abspath

Quick search

  • © Copyright 2008-2018, The SciPy community.
  • Last updated on Jul 24, 2018.
  • Created usingSphinx 1.6.6.

[8]ページ先頭

©2009-2025 Movatter.jp