问题描述
在以前的计算机上,当我尝试在 Windows 命令提示符下退出 Python 脚本时,您只需按 +.
On previous computers, when I would try to exit a Python script on the Windows command prompt, all you need to do is press +.
但是当我在计算机上执行此操作时,它告诉我KeyboardInterrupt":
But when I do that on my computer it tells me "KeyboardInterrupt":
C:\Windows\System32
>python
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> [I press ctrl+c]
KeyboardInterrupt
>>>
那么我该如何解决这个问题,以便我可以退出 Python 脚本?
So how do I fix this so I can exit the Python script?
谢谢.
编辑:
+ 有效,但我需要输入它作为代码.希望有一种快速简便的方法来退出脚本,但是很好.
Edit:
+ works, but I need to enter it as code. Was hoping for a quick and easy way to just exit the script, but oh well.
推荐答案
这确实取决于操作系统,也可能取决于您使用的 Python 版本.
It indeed depends on the OS, and probably on the version of Python you are using.
正如您所提到的,+ 不适用于使用 Python 3.6 的 Windows 10,但它适用于使用 Python 3.4 的 Windows 10.因此,你真的需要尝试看看什么对你有用.
As you mentioned, + does not work on your Windows 10 with Python 3.6, but it does work on my Windows 10 with Python 3.4. Therefore, you really need to try and see what works for you.
尝试以下命令,并保留有效的命令:
Try the following commands, and keep the one that works:
- +
- +
- + 然后
- +
- +
- + then
此外,以下内容适用于任何终端:
In addition, the following should work with any terminal:
exit()
然后quit()
然后
exit()
thenquit()
then
琐事:如果您输入 quit
并点击 ,控制台会告诉您,至少对于 Python 3.4:
Trivia: if you type quit
and hit , the console tells you, at least for Python 3.4:
使用 quit() 或 Ctrl-Z 加 Return 退出
这篇关于如何在命令提示符中退出 Python 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!