### Navigation

- index
- modules |
- next |
- previous |
- home|
- search|
- documentation »
- The IPython API »

# Module: `utils.tempdir`

TemporaryDirectory class, copied from Python 3.2.

This is copied from the stdlib and will be standard in Python 3.2 and onwards.

## 3 Classes

class `IPython.utils.tempdir.``TemporaryDirectory`(suffix='', prefix='tmp', dir=None)

  Bases: `object`

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

  > with TemporaryDirectory() as tmpdir:
  >   ...

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

  `__init__`(suffix='', prefix='tmp', dir=None)

class `IPython.utils.tempdir.``NamedFileInTemporaryDirectory`(filename, mode='w+b', bufsize=-1, **kwds)

  Bases: `object`

  `__init__`(filename, mode='w+b', bufsize=-1, **kwds)

    Open a file named filename in a temporary directory.

    This context manager is preferred over NamedTemporaryFile in stdlib tempfile when one needs to reopen the file.

    Arguments mode and bufsize are passed to open. Rest of the arguments are passed to TemporaryDirectory.

class `IPython.utils.tempdir.``TemporaryWorkingDirectory`(**kw)

  Bases: `IPython.utils.tempdir.TemporaryDirectory`

  Creates a temporary directory and sets the cwd to that directory. Automatically reverts to previous cwd upon cleanup. Usage example:

  > with TemporaryWorakingDirectory() as tmpdir:
  >   ...

  `__init__`(**kw)

### Navigation

- index
- modules |
- next |
- previous |
- home|
- search|
- documentation »
- The IPython API »