def restart_program():
"""Restarts the current program.
Note: this function does not return. Any cleanup action (like
saving data) must be done before calling this function."""
python = sys.executable
os.execl(python, python, * sys.argv)
本文介绍了一种使用Python标准库中的方法来重启当前正在运行的Python程序。通过调用`os.execl`并传递`sys.executable`参数,可以实现程序的自我重启。需要注意的是,在调用此函数之前必须完成所有必要的清理工作。
def restart_program():
"""Restarts the current program.
Note: this function does not return. Any cleanup action (like
saving data) must be done before calling this function."""
python = sys.executable
os.execl(python, python, * sys.argv)
转载于:https://www.cnblogs.com/Adalia-Ting/p/8779961.html
2066

被折叠的 条评论
为什么被折叠?