2 ms·
In the python shell, `exit` is a string containing a message to the effect of "You can leave the shell by sending EOF (CTRL-D)". I've seen HN commenters expres
by thaumasiotes 4y ago
In the python shell, `exit` is a string containing a message to the effect of "You can leave the shell by sending EOF (CTRL-D)".
I've seen HN commenters express extreme outrage over this ("They obviously know what you want to do, so why not just do it?!?!?"), but I love it. The first time I got that message, I considered it incredibly helpful, because sending EOF will work on any tool that reads from standard input, not just python. I hadn't known how to do that before the python shell taught me!
- mrguyorama 4y agoConsider that there is zero reason not to print that line, and exit anyway.
- thaumasiotes 4y agoThat's quite far from the truth. That's like saying that, if you read a textbook, there is zero reason to do any of the exercises. And from the implementation perspective, the python shell is trying to run a simple loop: 1. Read a line of python code. 2. Evaluate the code. 3. Print the result. Defining `exit` as the name of a string slots into that loop seamlessly. Defining it as a special keyword that is recognized by the shell, despite the fact that it has no special meaning to python, means you're no longer just reading python code; now you have to implement a separate parser solely for the purpose of handling this command.