For no particular reason (mainly just the joy of experimentation), I'm looking for a way to write a python script, that self-destroys after execution. One simple approach would be to determine the file, that is being called from the file itself and delete it afterwards as in:
import os
DIR_PATH = os.path.realpath(__file__)
os.remove(DIR_PATH)
which fails for obvious reasons (at least on windows) as the file is hold by the python process. How would I go about to achieve this? Bonus karma points for a real-world application on why anyone would do this.