在Python中暂停 [英] Pause in Python
问题描述
我正在运行命令行Python脚本从Windows任务栏通过一个快捷方式指向Python解释器与实际脚本作为参数。
I am running command-line Python scripts from the Windows taskbar by having a shortcut pointing to the Python interpreter with the actual script as a parameter.
脚本已经被处理,解释器终止并且输出窗口被关闭,这使得不能读取脚本输出。
After the script has been processed, the interpreter terminates and the output window is closed which makes it impossible to read script output.
什么是保持解释器窗口打开的最直接的方法:按任何键?
What is the most straightforward way to keep the interpreter window open until any key is pressed?
在批处理文件中,可以使用暂停结束脚本。我在python中发现的最接近的事情是 raw_input()
这是次最佳的,因为它需要按回车键(而不是任何键)。
In batch files, one can end the script with pause. The closest thing to this I found in python is raw_input()
which is sub-optimal because it requires pressing the return key (instead of any key).
任何想法?
推荐答案
一种方法是留下 raw_input()
在结尾,所以脚本等待你按Enter键,然后终止。
One way is to leave a raw_input()
at the end so the script waits for you to press Enter before it terminates.
这篇关于在Python中暂停的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!