[Python-Dev] quit() on the prompt

Ian Bicking ianb at colorstudy.com
Tue Mar 7 22:44:49 CET 2006

Frederick suggested a change to quit/exit a while ago, so it wasn't just 
a string with slight instructional purpose, but actually useful.  The 
discussion was surprisingly involved, despite the change really trully 
not being that big.  And everyone drifted off, too tired from the 
discussion to make a change.  I suppose it didn't help that the original 
proposal struck some people as too magic, while there were some more 
substantive problems brought up as well, and when you mix aesthetic with 
technical concerns everyone gets all distracted and worked up.  Anyway, 
I would like to re-propose one of the ideas that came up (originally 
from Ping?):

class Quitter(object):
     def __init__(self, name):
         self.name = name
     def __repr__(self):
         return 'Use %s() to exit' % self.name
     def __call__(self):
         raise SystemExit()
quit = Quitter('quit')
exit = Quitter('exit')

This is not very magical, but I think is more helpful than the current 
behavior.  It does not satisfy the "just do what I said" argument for 
not requiring the call (quit() not quit), but eh -- I guess it seemed 
like everything that didn't require a call had some scary corner case 
where the interpreter would abruptly exit.

Ian Bicking  /  ianb at colorstudy.com  /  http://blog.ianbicking.org

More information about the Python-Dev mailing list