NiBabel

Access a cacophony of neuro-imaging file formats

Previous topic

nibabel.tmpdirs.InTemporaryDirectory

This Page

Reggie -- the one

nibabel.tmpdirs.TemporaryDirectory

Inheritance diagram of TemporaryDirectory

class nibabel.tmpdirs.TemporaryDirectory(suffix='', prefix='tmp', dir=None, chdir=False)

Create and return a temporary directory. This has the same behavior as mkdtemp but can be used as a context manager.

Upon exiting the context, the directory and everthing contained in it are removed.

Examples

>>> import os
>>> with TemporaryDirectory() as tmpdir:
...     fname = os.path.join(tmpdir, 'example_file.txt')
...     with open(fname, 'wt') as fobj:
...         _ = fobj.write('a string\n')
>>> os.path.exists(tmpdir)
False
cleanup()