[issue44603] REPL: exit when the user types exit instead of asking them to explicitly type exit()
Eryk Sun
report at bugs.python.org
Sat Sep 25 16:00:38 EDT 2021
Eryk Sun <eryksun at gmail.com> added the comment:
Running the REPL with -S is unusual, so having to use sys.exit() or `raise SystemExit` in that case shouldn't be an issue.
A user who wants custom behavior for `exit` could override sys.displayhook() in the PYTHONSTARTUP file. For example:
import sys
import builtins
def displayhook(obj, prev_displayhook=sys.displayhook):
exit = getattr(builtins, 'exit', None)
if obj is exit and callable(exit):
exit()
else:
prev_displayhook(obj)
sys.displayhook = displayhook
> just note that you can always do Ctrl-D.
For the Windows console, Ctrl-D is not usually supported. It's supported when pyreadline is installed. Otherwise one has to type Ctrl-Z and enter. In IDLE it's Ctrl-D even in Windows, in which case the `exit` repr is wrong, as determined by setquit() in Lib/site.py.
----------
nosy: +eryksun
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44603>
_______________________________________
More information about the Python-bugs-list
mailing list