[Python-Dev] a quit that actually quits

Brett Cannon bcannon at gmail.com
Wed Dec 28 01:08:06 CET 2005


On 12/27/05, Ka-Ping Yee <python-dev at zesty.ca> wrote:
> It sounds to me like what is being proposed amounts to essentially
> "promote sys.exit to a builtin".  So why not do that?
>
> I see two options.  Either:
>
>     (a) Simply let __builtins__.exit = sys.exit.  Then we get:
>
>         >>> exit
>         <built-in function exit>
>
>         which may be enough of a clue that you type "exit()" to exit.
>
>     (b) If more handholding seems like a good idea, then:
>
>         class ExitHatch:
>             def __call__(self): sys.exit()
>             def __repr__(self): return '<Type "exit()" to exit Python.>'
>         __builtins__.exit = __builtins__.quit = ExitHatch()
>

I prefer (b) since this does need to be newbie-friendly and thus self
explaining.  I would prefer the name ExitInterpreter for the class and
including the keyboard shortcut in the message as well.

And Tim had a good point about PDAs and such; how are they supposed to
exit?  What if someone picked up Python for their Nokia S60 phone and
tried to exit from the interpreter?  Unless Nokia has tweaked
something I don't know how they would know to exit without knowing
about sys.exit() or raising SystemExit since I wouldn't know how to do
the equivalent Ctrl-D on a cell phone.

-Brett


More information about the Python-Dev mailing list