从python命令行退出 [英] Exiting from python Command Line

查看:61
本文介绍了从python命令行退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要从Python命令行退出,我必须键入exit().如果我输入exit,它会显示

To exit from Python command line, I have to type exit(). If I type exit, it says

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

通常,当您键入 exit 时,您想退出该程序.为什么解释器知道我要退出命令行时为什么会给我上述错误?为什么不退出呢?我知道这无关紧要,这是一个愚蠢的问题,但我很好奇.

Usually when you type exit, you would want to exit the program. Why does the interpreter give me the above error when it knows I am trying to exit the command line? Why doesn't it just exit? I know it doesn't matter and its a silly question but I am curious.

推荐答案

在我的python解释器中, exit 实际上是一个字符串,而不是一个函数-'使用Ctrl-D(即EOF))退出." .您可以通过输入 type(exit)

In my python interpreter exit is actually a string and not a function -- 'Use Ctrl-D (i.e. EOF) to exit.'. You can check on your interpreter by entering type(exit)

在活动的python中,正在发生的事情是exit是一个函数.如果不调用该函数,它将打印出对象的字符串表示形式.这是返回的任何对象的默认行为.只是设计人员认为人们可能会尝试键入exit退出解释器,因此他们使exit函数的字符串表示形式成为有用的信息.您可以通过键入 str(exit)甚至是 print exit 来检查此行为.

In active python what is happening is that exit is a function. If you do not call the function it will print out the string representation of the object. This is the default behaviour for any object returned. It's just that the designers thought people might try to type exit to exit the interpreter, so they made the string representation of the exit function a helpful message. You can check this behaviour by typing str(exit) or even print exit.

这篇关于从python命令行退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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