如何在获得输出后立即阻止 python.exe 关闭? [英] How can I stop python.exe from closing immediately after I get an output?

查看:45
本文介绍了如何在获得输出后立即阻止 python.exe 关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法可以阻止 python.exe 在完成后立即关闭?它关闭的速度比我读取输出的速度要快.

Is there any way I can stop python.exe from closing immediately after it completes? It closes faster than I can read the output.

这是程序:

width = float(input("Enter the width: "))
height = float(input("Enter the height: "))
area = width * height
print("The area is", area, "square units.")

推荐答案

你不能 - 全局,即对于每个 python 程序.这是一件好事 - Python 非常适合编写脚本(自动化内容),并且脚本应该能够在没有任何用户交互的情况下运行.

You can't - globally, i.e. for every python program. And this is a good thing - Python is great for scripting (automating stuff), and scripts should be able to run without any user interaction at all.

但是,您始终可以在程序结束时要求输入,从而有效地使程序保持活动状态,直到您按下回车键.在 Python 3 中使用 input("prompt: ")(或 Python 2 中的 raw_input("promt: ")).或者习惯于从命令行运行程序(即 python mine.py),程序将退出,但其输出仍然可见.

However, you can always ask for input at the end of your program, effectively keeping the program alive until you press return. Use input("prompt: ") in Python 3 (or raw_input("promt: ") in Python 2). Or get used to running your programs from the command line (i.e. python mine.py), the program will exit but its output remains visible.

这篇关于如何在获得输出后立即阻止 python.exe 关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆