[英]Python: Stop Auto Exiting Cmd Prompt
So I just started learning Python and just now set up my Notepad++ to run it via cmd prompt. 因此,我刚刚开始学习Python,现在设置了Notepad ++以通过cmd提示符运行它。 Is there a simple way to stop my cmd prompt from auto-exiting when I run a simple program?
运行简单程序时,是否有一种简单的方法可以阻止cmd提示自动退出? Do I need to ask for input every time or something or is there an easier way?
我是否每次都需要输入信息,或者有更简单的方法吗?
I tried raw_input('Press Enter to exit')
but no luck. 我尝试了
raw_input('Press Enter to exit')
但是没有运气。
Here's the program my introduction to python book started me with http://pastebin.com/ZVJrUzZZ 这是我对python书籍的介绍开始于http://pastebin.com/ZVJrUzZZ的程序
If it makes any difference I'm running it straight to python.exe in python version 3.2 如果有什么不同,我将直接在python 3.2版中将其直接运行到python.exe
What I personally like to do is have the Python script just run to completion without asking for input, then write a batch file (Windows) or shell script (Linux/UNIX) to do the "press any key" thing. 我个人想做的是让Python脚本在不要求输入的情况下运行到完成,然后编写批处理文件(Windows)或Shell脚本(Linux / UNIX)来完成“按任意键”操作。 That way when I run the script from the command line it doesn't needlessly prompt me for input.
这样,当我从命令行运行脚本时,它不会不必要地提示我输入。
You could write a batch file like this: 您可以这样编写批处理文件:
python.exe %*
pause
Save it as pypause.bat
and tell Notepad++ to run your Python scripts via this batch file instead of through python.exe
. 将其另存为
pypause.bat
并告诉Notepad ++通过此批处理文件而不是python.exe
运行Python脚本。
You have the right idea. 你有正确的主意。 You would need to put something like
raw_input()
somewhere before the script exits. 您需要在脚本退出之前在某处放置
raw_input()
之类的内容。
If this is python 3, use input
instead of raw_input
: 如果这是python 3,请使用
input
代替raw_input
:
if __name__ == '__main__':
print(approximate_size(1000000000000, False))
print (approximate_size(1000000000000))
input('Press Enter to exit')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.