"has" Operator
John Roth
johnroth at ameritech.net
Sat Jul 7 20:26:47 EDT 2001
"Paul Sidorsky" <paulsid at home.com> wrote in message
news:mailman.994543873.6493.python-list at python.org...
> Roman Suzi wrote:
>
> > if hasattr(myobject, "someattribute"):
> > foo()
> > else:
> > bar()
> > is clean enough, IMHO...
>
> Oops, I didn't know about hasattr(). Yes, that certainly does the
> trick. Though I have to say the syntax is a little odd (what with the
> quotes), but it's certainly sufficient. Thanks! Sorry to bother
> everyone.
Not a bother. We learn by watching everyone else ask questions! However,
the syntax is necessary, since "hasattr" is essentially a dictionary lookup.
John Roth
>
> --
> ======================================================================
> Paul Sidorsky Calgary, Canada
> paulsid at home.com http://members.home.net/paulsid/
>
More information about the Python-list
mailing list