Is except: ... pass bad style?
marduk
marduk at python.net
Thu Sep 9 16:38:50 EDT 2004
On Thu, 09 Sep 2004 15:29:08 -0400, Istvan Albert wrote:
> I personally don't like this, not because of pylint but because
> it feels like using the wrong solution for the problem.
> You could create a base class that has a method that
> does nothing and have all your objects inherit from that.
>
> This solution does properly communicate
> that the method is optional. Not to mention that you need
> to repeat the whole thing if used again in a different
> circumstance. Plus something could go wrong inside
> existing methods and you'd never know about it.
>
> Why risk all that?
This is probably overkill for my current circumstance, but I may consider
it in the future. Besides, the class in question is third-party and I'm
merely trying to call method if it exists (version n) and do nothing if it
doesn't exist (version n-1). Although I could subclass the third-party
class and override method()... but as I said, overkill for me right now as
I'm only using the object/method once.
I really liked the getattr suggestion. Thanks to all who responded.
----== 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 =---
More information about the Python-list
mailing list