Is except: ... pass bad style?
Aahz
aahz at pythoncraft.com
Thu Sep 9 13:06:02 EDT 2004
In article <pan.2004.09.09.16.26.16.985806 at python.net>,
marduk <marduk at python.net> wrote:
>
>I commonly use code like this
>
>try:
> # call optional method
> myobj.method()
>except AttributeError:
> # no biggie
> pass
>
>Occasionally I use pylint, which is a good tool, but in the above
>snippet pylint will complain that 'Except doesn't do anything'. True,
>but is that bad style? I know there are other ways of doing it, but
>of all the other "obvious" ones, this appears the most straight
>forward.
>
>Should I ignore pylint or is there a more Pythonic way to do this?
Neither. It's a perfectly good Pythonic idiom, but it's also likely to
be programmer error (mocking up the try/except structure and forgetting
to fill in the blanks later). So you should ignore pylint when it's
code you're familiar with (and have already double-checked your
intentions), but you should pay attention to pylint when you're writing
new code and checking it.
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
"A foolish consistency is the hobgoblin of little minds, adored by little
statesmen and philosophers and divines." --Ralph Waldo Emerson
More information about the Python-list
mailing list