5 ms·
I mean if you did that how would you access 'quit' if it is defined? It's a bit more complicated than it seems. Though I get your general point.
by resonantjacket5 6y ago
I mean if you did that how would you access 'quit' if it is defined? It's a bit more complicated than it seems.
Though I get your general point.
- cle 6y agoYou just access it, it's just a normal variable. $ python3 Python 3.8.6 (default, Nov 18 2020, 23:56:33) [GCC 9.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> quit Use quit() or Ctrl-D (i.e. EOF) to exit >>> q = quit >>> quit = "foo" >>> quit 'foo' >>> quit() Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'str' object is not callable >>> q() $
- colejohnson66 6y agoWait... So it’s possible to make it so you can’t use `quit()`? Just overwrite it without saving it?
- cle 6y agoYes. You can still send an EOF to quit (ctrl+d), or do "raise SystemExit()" which is all quit() does anyway: >>> print(inspect.getsource(quit.__call__)) def __call__(self, code=None): try: sys.stdin.close() except: pass raise SystemExit(code)