This documentation covers IPython versions 6.0 and higher. Beginning with version 6.0, IPython stopped supporting compatibility with Python versions lower than 3.3 including all versions of Python 2.7.

If you are looking for an IPython version compatible with Python 2.7, please use the IPython 5.x LTS release and refer to its documentation (LTS is the long term support release).

Module: utils.tempdir

This module contains classes - NamedFileInTemporaryDirectory, TemporaryWorkingDirectory.

These classes add extra features such as creating a named file in temporary directory and creating a context manager for the working directory which is also temporary.

2 Classes

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

Bases: object

__init__(filename, mode='w+b', bufsize=-1, add_to_syspath=False, **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(suffix=None, prefix=None, dir=None, ignore_cleanup_errors=False)

Bases: TemporaryDirectory

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

with TemporaryWorkingDirectory() as tmpdir: