"has" Operator

Fredrik Lundh fredrik at pythonware.com
Sun Jul 8 10:00:53 EDT 2001


Guido van Rossum wrote:

> Actually, Paul's proposal to write
>
>   x has y
>
> instead of
>
>   hasattr(x, 'y')
>
> has a nice Pythonic ring to it, and the fact that you have to use
> quotes with hasattr() has always bothered me.

well, you'd still need hasattr to deal with

    attr = "someattribute"
    if hasattr(myobject, attr):
        ...

and is it really obvious why the following code doesn't work?

    attr = "someattribute"
    if myobject has attr:
        ...

> right now, I'd say it's too little value for too much disturbance (a new
> keyword).

given the amount of other potentially disturbing stuff going
into 2.2, I doubt anyone would notice...

</F>





More information about the Python-list mailing list