I manage temporary files in my temporary file subdirectory, attempting to remove all the ones I've created when Python shuts down.

Class Variable prefix The prefix for all temp files. (type: str)
Instance Variable tempDir The subdirectory where I keep all of my temporary files, creating it if necessary. (type: str)
Instance Variable filePaths Full paths of temp files registered for deletion when Python shuts down. (type: set)
Method __init__ TempfileManager()
Method __del__ Removes my temp directory and all files in it when my instance gets deleted.
Method new Generates and returns a new, unique temporary file path, given the supplied extension (a string beginning with or lacking a dot).
Method rm Call with a filePath to delete a single specified file, immediately unless register is set True. In that case, registers the file path for deletion when Python shuts down.
prefix =
The prefix for all temp files. (type: str)
tempDir =
The subdirectory where I keep all of my temporary files, creating it if necessary. (type: str)
filePaths =
Full paths of temp files registered for deletion when Python shuts down. (type: set)
def __init__(self):

TempfileManager()

def __del__(self):

Removes my temp directory and all files in it when my instance gets deleted.

This should work consistently, so long as you never construct your own instance of me. Do everything through the tempfile function.

def new(self, ext, keep=False):

Generates and returns a new, unique temporary file path, given the supplied extension (a string beginning with or lacking a dot).

The file path will be in my temp directory, which I create if necessary. Creating the actual temp file is up to you, though I will delete it when Python shuts down or if you call rm with the file path. (Set the keep keyword True to prevent that deletion from happening.)

def rm(self, filePath=None, register=False):

Call with a filePath to delete a single specified file, immediately unless register is set True. In that case, registers the file path for deletion when Python shuts down.

Call with nothing to immediately delete all registered files.

API Documentation for pingspice, generated by pydoctor at 2021-09-18 08:41:11.