对于以下代码,如果在命令提示符下运行,则结果为: 1 2 三 4 5 6 1 2 三 4 5 6 . . . 在
如果在Pycharm中运行,则结果仅为: 1 2 三 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控制台中执行,重新启动应该可以工作了。在
相关问题 更多 >
编程相关推荐