[Python-ideas] "on" statement

Terry Reedy tjreedy at udel.edu
Thu Apr 1 19:50:08 CEST 2010


On 4/1/2010 11:15 AM, Robert Madole wrote:
> So I just wrote my 1-gazillionth "if hasattr('method', my_object):" and wanted badly to write this.
>
> 	if 'method' on my_object:

If you do not need the superclass search provided by hasattr,

   if 'method' in my_object.__dict__:

 >>> '__add__' in int.__dict__
True

But I otherwise agree with Nick.

Terry Jan Reedy




More information about the Python-ideas mailing list