如何在 Microsoft Windows 中执行时立即停止 Python 关闭 [英] How to stop Python closing immediately when executed in Microsoft Windows

查看:57
本文介绍了如何在 Microsoft Windows 中执行时立即停止 Python 关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始上大学,我们将使用 Python.我们真的什么都没做,所以我下载了程序并执行了一些打印命令,仅此而已.

I have just started college and we are going to be using python. We really have done nothing so I have downloaded the program and done some print commands, and that's it.

当我运行我的 .py 文件(一个 print 命令)它出现后立即关闭.我理解它为什么这样做——它给出了输出,所以它完成了它需要做的——但我也明白你可以阻止这种情况发生.

When I run my .py file (a print command) it immediately closes after appearing. I understand why it does this - it's given the output, so it's done what it needs to do - but I also understand that you can stop this from happening.

我环顾了这个网站,发现针对这个问题的所有解决方案都没有奏效,要么是我不理解,要么是我不理解.

I looked around this website and none of the solutions given to this question worked, either that or I didn't understand them.

是否有一个简单的命令可以输入到我的 IDLE 编辑器中,让程序暂停或其他什么?我已经按照某人的建议尝试了 input("prompt: ") ,但没有任何区别.

Is there a simple command I can input to my IDLE editor that will put the program on hold or something? I have tried input("prompt: ") as suggested by someone, and that made no difference.

如果没有此命令,有没有办法更改计算机上的设置,使程序不会自动关闭?

If there isn't a command for this, is there a way to change the settings on the computer so that programs don't auto close?

推荐答案

在 Python 3 中,将以下内容添加到代码末尾:

In Python 3, add the following to the end of your code:

input('Press ENTER to exit')

这将导致程序等待用户输入,按 ENTER 使程序完成.

This will cause the program to wait for user input, with pressing ENTER causing the program to finish.

您可以通过这种方式方便地双击 Windows 中的 script.py 文件.

You can double click on your script.py file in Windows conveniently this way.

这篇关于如何在 Microsoft Windows 中执行时立即停止 Python 关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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