[Python-Dev] a quit that actually quits

Fredrik Lundh fredrik at pythonware.com
Wed Dec 28 08:56:14 CET 2005


Ka-Ping Yee wrote:

> 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

the easiest way to solve this that I can think of right now is to add a
new sys variable that contains a copy of the most recent line read by
the interactive prompt.

    if sys.commandline.strip() in ("exit", "quit"):
        sys.exit()

</F>





More information about the Python-Dev mailing list