Gravatar I agree with this. I think it's similar to the phone company message in the US that states that you need to dial 1 first to call a number.

If you know that I need to dial 1, just do it for me!


Gravatar That always bugged me too. Maybe the message was supposed to be helpful, but to me it always comes across as veiled hostility. ("No, doofus, you've got to do it _this_ way.")

Does python-dev have anything to say on this?


Gravatar There is a big difference between a variable and a statement. You want 'exit' to be a statement (like 'print'). That is more work, and could not be overridden.

There is _nothing_ in python now preventing you from using 'exit' as a variable name.

Maybe Python should have an 'exit' statement, e.g. raise SystemExit(param),
but it's a little more difficult than you are presenting here.


Gravatar I am just talking about the interactive interpreter, not Python per se. Also, I am not arguing for a new statement or expression, just for a sane way to leave the interpreter.

It would be trivial to write something that catches the user's input (in fact, it does that already), then exit the interpreter if the user entered "exit" or "quit"... or define "exit" or "quit" bound ot objects that exit when their __repr__ is called (i.e. when typed on the command line), as I described in my post. My question was and is, why hasn't this been done already?


I work on windows (^Z) and cygwin (^D) on the same box, so have just learned to do "raise SystemExit", which works in both places....


Gravatar I took your idea and modified site.py. I renamed the existing method setquit() to setquit_old(), and created a slightly edited setquit():

def setquit():
__builtin__.quit = __builtin__.exit = exit = _Exit()

Above this, I inserted the class you mention, also slightly edited:

class _Exit:
"""define a class that will cause the interpreter to exit
when we type 'exit' """
def __init__(self):
if os.sep == ':':
print "you can use 'exit' or Cmd-Q to quit.n"
elif os.sep == '\':
print "you can use 'exit' or Ctrl-Z plus Return to exit.n"
else:
print "you can use 'exit' or Ctrl-D (i.e. EOF) to exit.n"
def __repr__(self):
raise SystemExit

Funny thing, though, even though the Python interpreter tells me (on XP) that I can quit by typing Ctrl-Z + return, it doesn't work. Instead, Ctrl-D works. And now of course, 'exit' works as well!

thanks
S


Gravatar This used to bug me as well, and I created an almost identical class which I had in my site.py for years. Then one day I typed:

>>> dir(__builtins__)

And the interpreter happily exited as soon as it got to 'exit'.

I think this is why it's not the default . It'd be very confusing if you didn't know why it was happening.

Take care,
-Brian


Gravatar Hm, yes... rather an a builtin, maybe it should a special case in the interpreter, or something.