如何阻止命令提示符在 python 中关闭? [英] How to stop command prompt from closing in python?

查看:67
本文介绍了如何阻止命令提示符在 python 中关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对python很陌生..我使用了代码

I am very new to python.. I used the code

x = input(" Hey what is your name " )       
print(" Hey, " + x)  
input(" press close to exit ")

因为我在互联网上寻找过这个问题并且知道你必须在最后放一些虚拟输入行来阻止命令提示符关闭但我仍然面临这个问题.. 请帮助

Because i have looked for this problem on internet and came to know that you have to put some dummy input line at the end to stop the command prompt from getting closed but m still facing the problem.. pls Help

我使用的是 python 3.3

I am using python 3.3

推荐答案

在 windows 上,关闭的是 CMD 控制台,因为 Python 进程存在于最后.

On windows, it's the CMD console that closes, because the Python process exists at the end.

要防止这种情况发生,请先打开控制台,然后使用命令行运行您的脚本.为此,请右键单击包含脚本的文件夹,选择 Open console here 并在控制台中输入 python scriptname.py.

To prevent this, open the console first, then use the command line to run your script. Do this by right-clicking on the folder that contains the script, select Open console here and typing in python scriptname.py in the console.

正如您所发现的,另一种方法是通过在末尾添加 input() 调用来推迟脚本结束.这允许脚本的用户选择脚本结束和控制台关闭的时间.

The alternative is, as you've found out, to postpone the script ending by adding a input() call at the end. This allows the user of the script to choose when the script ends and the console closes.

这篇关于如何阻止命令提示符在 python 中关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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