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

前端 未结 5 517
臣服心动
臣服心动 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 03:59

    Yes, you could use the following:

    import os
    import sys
    import subprocess
    
    # execute and remove after run
    (Your python code)
    # end of file
    
    dir = os.getcwd()
    os.remove(dir+'\%s' % sys.argv[0])
    

    This script can be modified of course, but besides that this should work

提交回复
热议问题