Restart python-script from within itself

前端 未结 9 1899
谎友^
谎友^ 2020-12-02 15:27

I have a python-based GTK application that loads several modules. It is run from the (linux) terminal like so:

./myscript.py --some-flag setting

9条回答
  •  执念已碎
    2020-12-02 16:08

    You're looking for os.exec*() family of commands.

    To restart your current program with exact the same command line arguments as it was originally run, you could use the following:

    os.execv(sys.argv[0], sys.argv)
    

提交回复
热议问题