[Patches] Having a builtin exit function in python

jose jose@sferacarta.com
Tue, 06 Nov 2001 10:52:23 +0100


Hi,

I don't know if this is the right mailing list to send this message,
anyway, I'm having the following problem and maybe I'm not the only one.
I think this interest every else programming with curses or slang.
As you know these libraries change the terminal to the raw mode,
and if your program aborts before it restores the terminal mode,
the EOF character is changed.
Take a look...

Python 2.0 (#3, Nov  3 2000, 13:02:11)
[GCC 2.95.2 20000220 (Debian GNU/Linux)] on linux2
Type "copyright", "credits" or "license" for more information.
 >>> quit
'Use Ctrl-D (i.e. EOF) to exit.'
 >>> ^D
 File "<stdin>", line 1
    ^
SyntaxError: invalid syntax
 >>> exit
'Use Ctrl-D (i.e. EOF) to exit.'
 >>> import sys
 >>> sys.exit(0)
-----------------------------------------------------------------------

How to solve this problem:


Why not to print the way to exit from python in like this...

Python 2.0 (#3, Nov  3 2000, 13:02:11)
[GCC 2.95.2 20000220 (Debian GNU/Linux)] on linux2
Type "copyright", "credits" or "license" for more information.
Type quit() or  Ctrl-D (i.e. EOF) to exit.

and  modify site.py like this...

# Define new built-ins 'quit' and 'exit'.
# These are simply strings that display a hint on how to exit.
#if os.sep == ':':
#    exit = 'Use Cmd-Q to exit.'
#elif os.sep == '\\':
#   exit = 'Use Ctrl-Z plus Return to exit.'
#else:
#    exit = 'Use Ctrl-D (i.e. EOF) to exit.'
import __builtin__
__builtin__.exit = __builtin__.quit = sys.exit
#del exit

I think it whould be very useful to have a builtin function quit() or 
exit() to avoid to import the sys module to exit from python.
site.py already imports sys module, why I have to import it again?
I modified site.py in my system. What about to have this modify in the 
official release?

Best regards
Jose Soares