[Python-Dev] a quit that actually quits (original) (raw)
Ronald Oussoren ronaldoussoren at mac.com
Tue Dec 27 15:27:52 CET 2005
- Previous message: [Python-Dev] a quit that actually quits
- Next message: [Python-Dev] a quit that actually quits
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 27-dec-2005, at 14:55, Christopher Armstrong wrote:
On 12/28/05, Reinhold Birkenfeld <reinhold-birkenfeld-_ _nospam at wolke7.net> wrote:
Fredrik Lundh wrote:
sourceforge just went off the air, so I'm posting this patch here, in order to distract you all from Christian's deque thread.
this silly little patch changes the behaviour of the interpreter so that "quit" and "exit" actually exits the interpreter. it does this by installing a custom excepthook that looks for NameErrors at the top level, in interactive mode only. What is wrong with something like this:
class Quitter: ... def repr(self): raise SystemExit ... exit = quit = Quitter() It could optionally check for top level too, of course. Not sure if this is what you mean by "check for top level too", but the obvious problem is that calling vars(builtins) (or similar) will cause your interpreter to exit. :)
Why must quit and exit be so special in the first place? They could
be plain functions,
or even something like::
class _QuitOrExit:
def __init__(self, name):
self.name = name
def __repr__(self):
return "Use %(name)s() to exit."%(self.__dict__)
def __call__(self):
raise SystemExit
quit = _QuitOrExit("quit")
exit = _QuitOrExit("exit")
Ronald
- Previous message: [Python-Dev] a quit that actually quits
- Next message: [Python-Dev] a quit that actually quits
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]