Download envs/kitoverlay/skimage/_shared/_tempfile.py from AVSim/simulation-package: direct link, hf CLI and curl.
- Browser
- Download file 760 Bytes
-
https://huggingface.co/datasets/AVSim/simulation-package/resolve/main/envs/kitoverlay/skimage/_shared/_tempfile.py
- Command line
-
hf download hf://datasets/AVSim/simulation-package/envs/kitoverlay/skimage/_shared/_tempfile.py
-
curl -L -o _tempfile.py https://huggingface.co/datasets/AVSim/simulation-package/resolve/main/envs/kitoverlay/skimage/_shared/_tempfile.py
760 Bytes
| from tempfile import NamedTemporaryFile | |
| from contextlib import contextmanager | |
| import os | |
| def temporary_file(suffix=''): | |
| """Yield a writeable temporary filename that is deleted on context exit. | |
| Parameters | |
| ---------- | |
| suffix : str, optional | |
| The suffix for the file. | |
| Examples | |
| -------- | |
| >>> import numpy as np | |
| >>> from skimage import io | |
| >>> with temporary_file('.tif') as tempfile: | |
| ... im = np.arange(25, dtype=np.uint8).reshape((5, 5)) | |
| ... io.imsave(tempfile, im) | |
| ... assert np.all(io.imread(tempfile) == im) | |
| """ | |
| with NamedTemporaryFile(suffix=suffix, delete=False) as tempfile_stream: | |
| tempfile = tempfile_stream.name | |
| yield tempfile | |
| os.remove(tempfile) | |