[PATCH] A compromise on case

Nick Mathewson nickm at mit.edu
Fri May 26 01:06:54 EDT 2000

On Tue, 23 May 2000 17:18:25 GMT, Nick Mathewson <nickm at mit.edu> wrote:
>So I tried to make a quick-and-dirty patch the Python interpreter to
>do something more reasonable.  Here's a sample interaction:
>[tracebacks omitted, long lines wrapped]
>    >>> print MAP(square, [1,2,3])
>    NameError: No such name as 'MAP'.  Perhaps you meant 'map'?
>    >>> import string, re
>    >>> print string.JOIN(['a', 'b', 'c'])
>    AttributeError: JOIN.  Perhaps you meant 'join'?

Update, for anybody who cares:

I substantially rewrote my patch after advice and comments from Martin
von Loewis, Guido, Mark Hammond, and Skip Montanaro; I've just sent
the latest version to the patches list.

It now handles all the cases above more efficiently and cleanly than
before, and it can now catch another kind of error altogether:

  >>> class NumHolder:
  ...     def __init__(self, num):
  ...         self.x = num
  ...     def get(self):
  ...         return x
  >>> NumHolder(5).get()
  Traceback (most recent call last):
     File "<stdin>", line 1, in ?
     File "<stdin>", line 5, in get
  NameError: No such name as 'x'. Perhaps you meant 'self.x'?

Forgetting 'self' is one of the most common beginner errors on
comp.lang.python.  The extra code required to detect it: 4 lines!

Nick Mathewson     <nickm at mit.edu>     http://www.mit.edu/~nickm/

More information about the Python-list mailing list