对于以下代码,如果在命令提示符下运行,结果为: 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()