Restarting a self-updating python script

前端 未结 8 770
小鲜肉
小鲜肉 2020-11-30 18:48

I have written a script that will keep itself up to date by downloading the latest version from a website and overwriting the running script.

I am not sure what the

8条回答
  •  南笙
    南笙 (楼主)
    2020-11-30 19:04

    To additionally support script calls with Python's "-m" parameter the following can be used (based on the Alex's answer; Windows version):

    os.spawnl(os.P_WAIT, sys.executable, *([sys.executable] +
        (sys.argv if __package__ is None else ["-m", __loader__.name] + sys.argv[1:])))
    sys.exit()
    

提交回复
热议问题