I use shelve because tempFile and dict [] objects cannot be stored in different modules. As you have discovered, a call to .clear () does not clear the contents of a permanent object on disk, leaving the r + w file on disk after exiting. (Similar to a vulnerability without using software) You can remove a shelf when done using:
import os import shelve shelve_name = 'shelve_name' shelve_contents = shelve.open(shelve_name, flag='c', protocol=None, writeback=False) shelve_file = (os.getcwd()+'/'+shelve_name) os.remove(shelve_file)
source share