[Python-ideas] exit as a statement

Aahz aahz at pythoncraft.com
Wed Feb 20 16:57:15 CET 2008

On Wed, Feb 20, 2008, BJ?rn Lindqvist wrote:
> An idea I have thought about for a while and it makes sense to me...
> $ python
> Python 2.4.2 (#1, Oct 13 2006, 17:17:08)
> [GCC 4.1.0 (SUSE Linux)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> exit
> 'Use Ctrl-D (i.e. EOF) to exit.'
> Argh! Do what I mean, stupid Python! And it is Ctrl+Z on Windows, not
> Ctrl-D. So exit could be a statement that does the same thing that
> sys.exit() does currently. Bare "exit" to terminate with return code
> 0, and "exit X" to terminate with return code X.

Python 2.5.1 (r251:54863, Sep 27 2007, 12:17:47) 
[GCC 3.3.3 (NetBSD nb3 20040520)] on netbsd3
Type "help", "copyright", "credits" or "license" for more information.
>>> exit
Use exit() or Ctrl-D (i.e. EOF) to exit
>>> exit()

This is essential because we do NOT want to add a new statement; however,
we can make ``exit`` an object with a repr() that tells people to call
it.  IIRC, on Windows, it does say "Ctrl-Z" -- but it doesn't matter,
because IIRC Ctrl-D does work on Windows.  (I won't bother to fire up my
Windows box to check.)

In theory, we could make ``exit`` a property() that raises SystemExit,
but that seems to magical for my taste (and other people agreed).
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"All problems in computer science can be solved by another level of     
indirection."  --Butler Lampson

More information about the Python-ideas mailing list