Suggesting methods with similar names

Bengt Richter bokr at
Thu Mar 31 02:15:39 CEST 2005

On Wed, 30 Mar 2005 17:55:32 GMT, "Raymond Hettinger" <vze4rx4y at> wrote:

>> Working in the interactive window I receive an error like
>> this when I write the wrong method name:
>> >>> table.addGlas()
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in ?
>> AttributeError: 'Surface' object has no attribute 'addGlas'
>> Is it possibile to make the object give a better answer: a short list
>> of few method names similar to the one I've misspelled?
>> Thank you, __getattr__ does what I need :-)
>> A smart help can be designed easely...
>The idea is a winner.  When you're done, consider posting the result as an ASPN
>cookbook recipe.
Interactively, I often use dir(whatever) to find methods, but I sure wish dir had
some keyword arguments to limit the returned info various ways, e.g., methods
of the immediate class, not the whole mro, and optionally without the __xxx__ methods.
Ditto with help().

BTW, when are we going to be able to write

class Foo(object):

so we can implement smart help as a decorator?

I.e., the above decorator syntax would be a non-intrusive way of spelling

class Foo(object):
    __metaclass__ = classdeco

(haven't thought about cascaded decorators in this context ;-)

Bengt Richter

More information about the Python-list mailing list