-2

Python 2.7 版

我尝试了一个代码,它没有给出任何错误。当我运行程序时,它只显示了几毫秒的结果,然后窗口立即关闭。是否有任何方法可以永久显示结果并仅按我的意愿关闭窗口而不是自行关闭?

4

3 回答 3

0

I am assuming that you are running it by double clicking your .py script. Your OS (Windows I assume) will then close the calling 'cmd' terminal once the script has finished, you could circumvent this by starting the terminal manually (just goto start -> execute and enter cmd) to run the script so it won't close automatically.

于 2013-06-03T10:01:52.810 回答
0

只需raw_input()在脚本末尾使用一个。这将提示输入一个字符串,然后您可以按“Enter”关闭窗口

于 2013-06-03T09:01:40.210 回答
0

发生这种情况是因为您的代码尽可能快地运行并在完成时停止。当您通过在 Windows 操作系统上双击打开 .py 程序时;它在 cmd 窗口中打开程序,当代码运行完毕后,它再次关闭窗口。您只指定它执行一些计算,然后停止。因此,为了保持程序运行类型raw_input(),或者如果在代码末尾使用 python 3 input(),以防止它一直运行,直到你按下一个键。

于 2017-03-29T02:03:01.580 回答