pythonexit退出
① python exit() 怎麼用
exit可能被site自定義文件改了,你列印一下exit的值,應該變成字元串了。需要咨詢系統管理員。
正常的site文件exit是這樣的:
$python
Python2.7.10(default,Aug132015,17:53:56)
[GCC4.7.2]onlinux2
Type"help","right","credits"or"license"formoreinformation.
>>>exit.__mole__
'site'
>>>importsite
>>>site.__file__
'/home/sylecn/opt/lib/python2.7/site.pyc'
>>>printexit
Useexit()orCtrl-D(i.e.EOF)toexit
>>>printtype(exit)
<class'site.Quitter'>
>>>
這是原版的site.py exit的定義:
defsetquit():
"""Definenewbuiltins'quit'and'exit'.
.
.
"""
ifos.sep==':':
eof='Cmd-Q'
elifos.sep=='\':
eof='Ctrl-ZplusReturn'
else:
eof='Ctrl-D(i.e.EOF)'
classQuitter(object):
def__init__(self,name):
self.name=name
def__repr__(self):
return'Use%s()or%stoexit'%(self.name,eof)
def__call__(self,code=None):
#,butlistenwhentheir
#stdinwrapperisclosed.
try:
sys.stdin.close()
except:
pass
raiseSystemExit(code)
__builtin__.quit=Quitter('quit')
__builtin__.exit=Quitter('exit')
② python輸入exit()後為什麼直接退出了
打開的不是同一個程序,
第一張圖是cmd命令提示符。
第二張圖是IDLE。
自然效果不一樣
③ python 中的exit()怎麼用
是sys模塊中的exit函數嗎?
sys.exit() 引發一個 SystemExit異常,若沒有捕獲這個異常,Python解釋器會直接退出;捕獲這個異常可以做一些額外的清理工作。0為正常退出,其他數值(1-127)為不正常,可拋異常事件供捕獲。
exit() 跟 C 語言等其他語言的 exit() 應該是一樣的。
如果是你手動調用這個函數就是要自己處理異常的情況。
④ 在linux的終端怎麼退出python命令行
Python2.7.7(default,Jun32014,01:46:20)
[GCC4.9.020140521(prerelease)]onlinux2
Type"help","right","credits"or"license"formoreinformation.
>>>quit
Usequit()orCtrl-D(i.e.EOF)toexit
>>>
使用 quit(), exit(), 或者Ctrl-D退出命令行。
如果解決了您的問題請採納!
如果未解決請繼續追問!
⑤ 請教Python如何終止主程序
return break 都可以終止函數的運行
exit(0) # 無錯誤退出
exit(1) # 有錯誤退出
這兩條語句一般都會加在程序的最後 因為exit是迫使系統去終止程序的運行!
⑥ Python退出命令的總結
@(Python入門)
[TOC]
quit raises the SystemExit exception behind the scenes.
Furthermore, if you print it, it will give a message:
This functionality was included to help people who do not know Python. After all, one of the most likely things a newbie will try to exit Python is typing in quit .
Nevertheless, quit should not be used in proction code. This is because it only works if the site mole is loaded. Instead, this function should only be used in the interpreter.
exit is an alias for quit (or vice-versa). They exist together simply to make Python more user-friendly.
Furthermore, it too gives a message when printed:
However, like quit , exit is considered bad to use in proction code and should be reserved for use in the interpreter. This is because it too relies on the site mole.
sys.exit raises the SystemExit exception in the background. This means that it is the same as quit and exit in that respect.
Unlike those two however, sys.exit is considered good to use in proction code. This is because the sys mole will always be there.
os._exit exits the program without calling cleanup handlers, flushing stdio buffers, etc . Thus, it is not a standard way to exit and should only be used in special cases. The most common of these is in the child process(es) created by os.fork .
Ctrl+Z is a qucik-operation of exit and quit , which means Ctrl+Z is the same with them.
use
to exit, so u don't need to import sys first.
The site mole (which is imported automatically ring startup, except if the -S command-line option is given) adds several constants to the built-in namespace. They are useful for the interactive interpreter shell and should not be used in programs.
Objects that when printed, print a message like 「Use quit() or Ctrl-D (i.e. EOF, end of file) to exit」, and when called, raise SystemExit with the specified exit code.
Exit from Python. This is implemented by raising the SystemExit exception, so cleanup actions specified by finally clauses of try statements are honored, and it is possible to intercept the exit attempt at an outer level.
The optional argument arg can be an integer giving the exit status (defaulting to zero), or another type of object. If it is an integer, zero is considered 「successful termination」 and any nonzero value is considered 「abnormal termination(結局)」 by shells and the like. Most systems require it to be in the range 0–127, and proce undefined results otherwise. Some systems have a convention for assigning specific meanings to specific exit codes, but these are generally underdeveloped; Unix programs generally use 2 for command line syntax errors and 1 for all other kind of errors. If another type of object is passed, None is equivalent to passing zero, and any other object is printed to stderr and results in an exit code of 1. In particular, sys.exit ( "some error message" ) is a quick way to exit a program when an error occurs.
Since exit() ultimately 「only」 raises an exception, it will only exit the process when called from the main thread, and the exception is not intercepted.
Changed in version 3.6: If an error occurs in the cleanup after the Python interpreter has caught SystemExit (such as an error flushing buffered data in the standard streams), the exit status is changed to 120.
https://stackoverflow.com/questions/19747371/python-exit-commands-why-so-many-and-when-should-each-be-used
https://docs.python.org/3/library/constants.html#quit
https://docs.python.org/3/library/sys.html#sys.exit
http://grokbase.com/t/python/python-list/042qh9j55e/gripe-use-ctrl-d-i-e-eof-to-exit
⑦ python如何在終端退出
有時為了方便經常會在命令行敲python代碼,但是用了不記得怎麼退出了,只能關閉窗口,
退出方法:在>>>後面 輸入 exit()就行了
cmd中如何退出Python
(1)在命令行上輸入exit()
(2)在命令行上輸入quit()
推薦學習《python教程》
好像還有一種方法是在命令行上輸入Ctrl+Z,
除此之外,還可以使用
quit() 回車
control+z 回車
注意上面exit和quit後面都有括弧()。
⑧ python如何用戶直接輸入「exit」這個字元串退出 新手急急急
在循環獲取鍵盤輸入的時候加入判斷,如果輸入字元為exit,那麼跳出循環,跳出程序
希望我的回答對你有幫助~
⑨ cmd下如何退出python
進入:
直接輸入python即可,
相關推薦:《Python入門教程》
退出:
1:輸入exit(),回車
2:輸入quit(),回車
3:輸入ctrl+z,回車