반응형
Python에는 이름이 비슷한 두 개의 함수, exit ()
및 sys.exit ()
가 있습니다. 차이점은 무엇이며 언제 다른 것을 사용해야합니까?
해결 방법
static PyObject *
sys_exit(PyObject *self, PyObject *args)
{
PyObject *exit_code = 0;
if (!PyArg_UnpackTuple(args, "exit", 0, 1, &exit_code))
return NULL;
/* Raise SystemExit so callers may catch it or clean up. */
PyErr_SetObject(PyExc_SystemExit, exit_code);
return NULL;
}
class Quitter(object):
def __init__(self, name):
self.name = name
def __repr__(self):
return 'Use %s() or %s to exit' % (self.name, eof)
def __call__(self, code=None):
# Shells like IDLE catch the SystemExit, but listen when their
# stdin wrapper is closed.
try:
sys.stdin.close()
except:
pass
raise SystemExit(code)
__builtin__.quit = Quitter('quit')
__builtin__.exit = Quitter('exit')
참조 페이지 https://stackoverflow.com/questions/6501121
반응형
'파이썬' 카테고리의 다른 글
파이썬 목록에서 "x"개의 고유 번호를 어떻게 선택합니까? (0) | 2020.09.29 |
---|---|
파이썬 쌍을 생성하는 비단뱀적인 방법 (0) | 2020.09.29 |
파이썬 SQLAlchemy + SQL 주입 (0) | 2020.09.29 |
파이썬 Ubuntu에 lxml을 설치하는 방법 (0) | 2020.09.29 |
파이썬 사전 키가 목록에서 일치합니다. 키 / 값 쌍 가져 오기 (0) | 2020.09.29 |
댓글