如何在命令提示符中退出 Python 脚本? [英] How to exit Python script in Command Prompt?

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

问题描述

在以前的计算机上,当我尝试在 Windows 命令提示符下退出 Python 脚本时,您只需按 ctrl+c.

On previous computers, when I would try to exit a Python script on the Windows command prompt, all you need to do is press ctrl+c.

但是当我在计算机上执行此操作时,它告诉我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?

谢谢.

编辑:
ctrl+z 有效,但我需要输入它作为代码.希望有一种快速简便的方法来退出脚本,但是很好.

Edit:
ctrl+z 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.

正如您所提到的,ctrl+C 不适用于使用 Python 3.6 的 Windows 10,但它适用于使用 Python 3.4 的 Windows 10.因此,你真的需要尝试看看什么对你有用.

As you mentioned, ctrl+C 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:

  • ctrl+C
  • ctrl+D
  • ctrl+Z 然后 返回
  • ctrl+C
  • ctrl+D
  • ctrl+Z then Return

此外,以下内容适用于任何终端:

In addition, the following should work with any terminal:

  • exit() 然后 返回
  • quit() 然后 返回
  • exit() then Return
  • quit() then Return

琐事:如果您输入 quit 并点击 Return,控制台会告诉您,至少对于 Python 3.4:

Trivia: if you type quit and hit Return, the console tells you, at least for Python 3.4:

使用 quit() 或 Ctrl-Z 加 Return 退出

Use quit() or Ctrl-Z plus Return to exit

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

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