Context managers for managing temporary files and directories.
Installation:
$ pip install temporary
The temporary directory is created when entering the context manager, and deleted when exiting it:
This time let's make the temporary directory our working directory:
The suffix, prefix, and parent_dir options are passed to the standard tempfile.mkdtemp()
function:
This function can also be used as a decorator, with the in_temp_dir
alias:
The temporary file is created when entering the context manager and deleted when exiting it.
The user may also supply some content for the file to be populated with:
The temporary file can be placed in a custom directory:
If, for some reason, the user wants to delete the temporary file before exiting the context, that's okay too: