Open `path` with `mode` and return the file object. If ``path`` is a URL, it will be downloaded, stored in the `DataSource` `destpath` directory and opened from there. Parameters ---------- path : str or pathlib.Path Local file path or URL to open. mode : str,
(path, mode='r', destpath=os.curdir, encoding=None, newline=None)
| 152 | _file_openers = _FileOpeners() |
| 153 | |
| 154 | def open(path, mode='r', destpath=os.curdir, encoding=None, newline=None): |
| 155 | """ |
| 156 | Open `path` with `mode` and return the file object. |
| 157 | |
| 158 | If ``path`` is a URL, it will be downloaded, stored in the |
| 159 | `DataSource` `destpath` directory and opened from there. |
| 160 | |
| 161 | Parameters |
| 162 | ---------- |
| 163 | path : str or pathlib.Path |
| 164 | Local file path or URL to open. |
| 165 | mode : str, optional |
| 166 | Mode to open `path`. Mode 'r' for reading, 'w' for writing, 'a' to |
| 167 | append. Available modes depend on the type of object specified by |
| 168 | path. Default is 'r'. |
| 169 | destpath : str, optional |
| 170 | Path to the directory where the source file gets downloaded to for |
| 171 | use. If `destpath` is None, a temporary directory will be created. |
| 172 | The default path is the current directory. |
| 173 | encoding : {None, str}, optional |
| 174 | Open text file with given encoding. The default encoding will be |
| 175 | what `open` uses. |
| 176 | newline : {None, str}, optional |
| 177 | Newline to use when reading text file. |
| 178 | |
| 179 | Returns |
| 180 | ------- |
| 181 | out : file object |
| 182 | The opened file. |
| 183 | |
| 184 | Notes |
| 185 | ----- |
| 186 | This is a convenience function that instantiates a `DataSource` and |
| 187 | returns the file object from ``DataSource.open(path)``. |
| 188 | |
| 189 | """ |
| 190 | |
| 191 | ds = DataSource(destpath) |
| 192 | return ds.open(path, mode, encoding=encoding, newline=newline) |
| 193 | |
| 194 | |
| 195 | @set_module('numpy.lib.npyio') |
searching dependent graphs…