[Python-Dev] quit() on the prompt

Brett Cannon brett at python.org
Wed Mar 8 00:33:05 CET 2006


On 3/7/06, Ian Bicking <ianb at colorstudy.com> wrote:
> 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.

+1 from me.  Only change I would make is pass an argument to
SystemExit() such as "%s() called", although the chances of this
exception being caught is very slim.

-Brett


More information about the Python-Dev mailing list