On 27-dec-2005, at 14:55, Christopher Armstrong wrote:
On 12/28/05, Reinhold Birkenfeld
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