checking for the existence of an attribute
Dave Kuhlman
dkuhlman at rexx.com
Sun Oct 12 14:04:12 EDT 2003
Bob Roberts wrote:
> I'm sure there must be a better way to do this:
>
> try:
> if item.page:
> DoSomething()
> except AttributError:
> pass
>
> Is there a simple way to check if item has "page" as one of its
> attributes?
Look at built-in function `getattr`.
http://www.python.org/doc/current/lib/built-in-funcs.html
Dave
--
Dave Kuhlman
http://www.rexx.com/~dkuhlman
dkuhlman at rexx.com
More information about the Python-list
mailing list