Having a builtin exit function in python interpreter

Andrew Dalke dalke at dalkescientific.com
Tue Nov 6 19:34:18 CET 2001


zammon at libero.it (forwarding from Jose Soares):
>> I think this interest every else programming with curses or slang.

But not those not programming terminal applications.

>> >>> import sys
>> >>> sys.exit(0)
>> -----------------------------------------------------------------------
>>
>> How to solve this problem:

>> __builtin__.exit = __builtin__.quit = sys.exit

The 'exit' and 'quit' builtins are strings that hint to the
programmer that those commands don't work as expected.  The
key part is 'expected.'  Beginning Python developers don't
expect that 'exit()' is require to exit and would be confused
if typing 'exit' by itself returns  "<built-in function exit>".
I suspect they wouldn't think to try 'exit()'.

Those programming terminal apps are rare, and usually able
to figure out how to tweak site.py to make the way they want
it to be.

>> 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.

Another way to exit, without importing sys, is

raise SystemExit

>> I modified site.py in my system. What about to have this modify in the
>> official release?

You could also have a 'sitecustomize.py' in your working directory
which would do this for you, instead of modifying site.py.

So -1 for me on your proposal.  Makes things more complicated for
the people for which it is designed.

                    Andrew
                    dalke at dalkescientific.com






More information about the Python-list mailing list