How to make scripts auto-delete at the end of execution?

Serban Razvan picture Serban Razvan · Apr 11, 2012 · Viewed 28k times · Source

Is it possible to make a python script that will delete the .py file at the end of its execution (self-delete) in windows?

Answer

Neomind picture Neomind · Dec 12, 2013

This way makes your program non OS dependant.

from os import remove
from sys import argv

remove(argv[0])

Bonus points: When parsing arguments the very first argument that you get in sys.argv is equals to "path-to-filename/filename.py"