tags:

views:

31

answers:

2

Hello.... So I have a python program that ends up leaving a .dat file from the shelve function behind after execution. I would like my program to delete or clear that file once it is done. My textbook only mentions how to create a .dat file but not how to clear it. Any good commands out there to take care of this? I don't need the .dat file again after my program runs to completion.

+1  A: 

Register an atexit handler to do the cleanup for you (as described in the documentation here).

ChristopheD
A: 

This is easy:

import sys, os
sys.atexit.register( os.remove, path_to_file )

runs os.remove( path_to_file ) when the Python interpreter exists in a normal (not killed/crashed) way. But you need to make sure the file is closed by then.

THC4k