본문 바로가기
파이썬

파이썬 Python에서 exit ()와 sys.exit ()의 차이점

by º기록 2020. 9. 29.
반응형

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

 

 

반응형

댓글