[英]How to restart a program in Pycharm?
对于以下代码,如果在命令提示符下运行,则结果为:1 2 3 4 5 6 1 2 3 4 5 6。 。 。
如果在Pycharm中运行,则结果仅为:1 2 3 4 5 6.也就是说,restart_program()在Pycharm中不产生任何结果。
import sys
import os
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)
if __name__ == "__main__":
for i in range(1,10,1):
print i
if i>5:
restart_program()
更改运行配置以使用Python控制台运行脚本对我来说很成功。
打开“运行”菜单(或单击运行按钮左侧的箭头),然后单击“编辑配置...”。 您的默认配置应显示。 在“配置”->“执行”部分中,选中“使用Python控制台运行”,然后保存更改。
现在,当使用编辑后的运行配置并重新启动后,您的脚本将通过Python控制台执行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.