[Python-Dev] a quit that actually quits (original) (raw)
Fredrik Lundh fredrik at pythonware.com
Wed Dec 28 11:40:33 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 ]
Jeremy Kloth wrote:
Ka-Ping Yee wrote: > I'd be happy with having Python exit when the user types just plain > 'exit' without parentheses, but only in that case, not others. > However, i'm starting to think that may be impossible to implement. > I can't think of any way to make 'print exit' not exit, for example.
OK, here's one: def quithook(obj, exit=builtins.exit, displayhook=sys.displayhook): if obj is exit: raise SystemExit displayhook(obj) sys.displayhook = quithook It does, however, fall into the whole issue of chaining that Skip brought up earlier.
as well as various introspection-related issues:
>>> import foo
>>> cb = foo.getcallback()
>>> # let's see what it is
>>> cb
$
(by the way, it's "builtin", not "builtins". the former is a module, the latter a CPython implementation detail)
- 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 ]