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

前端 未结 5 552
臣服心动
臣服心动 2020-12-03 03:15

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

5条回答
  •  误落风尘
    2020-12-03 04:00

    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"

提交回复
热议问题