This module contains a class TempDir, which represents a temporary directory.
The class TempDir has been designed with python’s with statement in mind. This way, we can guarantee that temporary files created with instances of this class will be deleted:
from pyvhist.tempdir import TempDir
with TempDir() as tmp:
tmpfile1 = tmp.createTempFile("intermediate-results1")
tmpfile2 = tmp.createTempFile("intermediate-results2")
doSomeWork(tmpfile1, tmpfile2)
# temporary files have been deleted at this point, even if "doSomeWork"
# threw an exception
A class, which represents a temporary directory in the file system. You can use this class to create temporary files, which will be automatically deleted.
Returns the path of the temporary directory, which is associated with this instance of TempDir.
Creates a new tempfile with the name filename. TempDir will create subfolders for each file to make sure that there are no name clashes between temporary files with the same name. Therefore, the following code will return two distinct temporary files:
with TempDir() as tmp:
tempfile1 = tmp.createTempFile("intermediate-results")
tempfile2 = tmp.createTempFile("intermediate-results")