[Python-Dev] a quit that actually quits

Ka-Ping Yee python-dev at zesty.ca
Wed Dec 28 06:25:13 CET 2005


On 2005年12月28日, Fredrik Lundh wrote:
> Ka-Ping Yee wrote
> > It sounds to me like what is being proposed amounts to essentially
> > "promote sys.exit to a builtin".
> no, what's being proposed is what the subject says: a quit/exit command
> that actually quits, instead of printing a "you didn't say please!" message.

Okay, that would be fine. It's just that the solutions so far that
work without parentheses are a bit too magical for me.
Fredrik's NameError-based proposal (exit when there's an exception
with no tb_next that says "name 'exit' is not defined") causes the
interpreter to quit when you enter any expression involving 'exit'.
 print exit # seems surprising
 [3, 4, 5, exit] # seems surprising
 'a' in 'xyz' or exit # desirable or undesirable?
 del exit # actually happened to me
 x = exit # seems surprising
Reinhold's proposal (exit when sys._getframe(1).f_code.co_names
is ("exit",)) causes the interpreter to quit whenever any function
attempts to print out or represent 'exit', as long as it doesn't
mention any other variables.
 print exit # seems surprising
 [3, 4, 5, exit] # seems surprising
 'a' in 'xyz' or exit # desirable or undesirable?
 def foo():
 print exit
 foo() # seems surprising
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.
("'exit'" is a shorthand for "'exit' or 'quit'" above.)
-- ?!ng


More information about the Python-Dev mailing list

AltStyle によって変換されたページ (->オリジナル) /