Is except: ... pass bad style?
Chris Cioffi
evenprimes at gmail.com
Thu Sep 9 14:53:04 EDT 2004
I think that the getattr option would be your best/cleanest option.
For best results, combine with the Null object pattern.
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/68205
getattr(myobj, 'method', Null)()
Clean, concise, and clear. Just like most of the rest of Python. ;-)
Chris
On Thu, 09 Sep 2004 12:56:55 -0500, marduk <marduk at python.net> wrote:
>
> Based on all the responses received thus far, I thought of a way of
> doing it without an exception:
>
> myobj.__dict__.get('method', lambda : None)()
>
> Which is okay if you don't care about the return value of the
> method (in my examples I'm assuming .method() just does something
> (and returns None). But it's a lot uglier I think than the try/except
> block.
>
> ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
> http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
> ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
Still searching for an even prime > 2!
More information about the Python-list
mailing list