Is except: ... pass bad style?

Nicolas Fleury nid_oizo at yahoo.com_removethe_
Thu Sep 9 21:17:05 EDT 2004


marduk wrote:

> I commonly use code like this
> 
> try:
>     # call optional method
>     myobj.method()
> except AttributeError:
>     # no biggie
>     pass
> 

The problem with that solution is that some code in method() might raise 
  an AttributeError exception, and the code is broken.  Using hasattr or 
getattr is definitely better.

Regards,
Nicolas



More information about the Python-list mailing list