Is except: ... pass bad style?

Brandon Craig Rhodes brandon at ten22.rhodesmill.org
Thu Sep 9 20:59:13 CEST 2004


Michael Hudson <mwh at python.net> writes:

> marduk <marduk at python.net> writes:
>
>> I commonly use code like this
>> 
>> try:
>>     # call optional method
>>     myobj.method()
>> except AttributeError:
>>     # no biggie
>>     pass
>
> try:
>     meth = myobj.method
> except AttributeError:
>     pass
> else:
>     meth()

I'm confused - why not

    meth = getattr(myobj, method)
    if meth:
        meth()

-- 
Brandon Craig Rhodes   brandon at rhodesmill.org   http://rhodesmill.org/brandon



More information about the Python-list mailing list