On Tue, Jun 10, 2008 at 10:54:45AM -0700, David King wrote:
>> So where does the 'Use quit() or Ctrl-D (i.e. EOF) to exit'
>> message come from? If it has code to output that message, which
>> means it knows exactly what the user wants, why not just make
>> that code do what the user wanted in the first place? The only
>> reason I can honestly conceive of is spite.
>
> It's the value of the 'exit' (or 'quit') variable.
>
> >>> print "%% %s %%" % exit
> % Use exit() or Ctrl-D (i.e. EOF) to exit %
> >>> exit = "There's no escape"
> >>> exit
> "There's no escape"

No it isn't.  Not as of Python 2.5.

In Python 2.5 there's the following block of code:

    def setquit():
        """Define new built-ins 'quit' and 'exit'.
        These are simply strings that display a hint on how to exit.

        """
        if os.sep == ':':
            eof = 'Cmd-Q'
        elif os.sep == '\\':
            eof = 'Ctrl-Z plus Return'
        else:
            eof = 'Ctrl-D (i.e. EOF)'

        class Quitter(object):
            def __init__(self, name):
                self.name = name
            def __repr__(self):
                return 'Use %s() or %s to exit' % (self.name, eof)
            def __call__(self, code=None):
                # Shells like IDLE catch the SystemExit, but listen when
                # their
                # stdin wrapper is closed.
                try:
                    sys.stdin.close()
                except:
                    pass
                raise SystemExit(code)
        __builtin__.quit = Quitter('quit')
        __builtin__.exit = Quitter('exit')

Now that goes over the line from "a string variable because we're too
lazy to do what we know the user wants to do" to "ha ha you didn't say
Simon Says".

Why go to all that elaborate trouble to figure out what the user wants
to do, and then after having done that, just deliver a lecture about how
the user should have done it the Proper Approved Way?

Just this alone displays the sort of contempt for actual humans that
makes me not want to ever use Python for a serious project.

--Dave

Reply via email to