A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2005-July/054669.html below:

[Python-Dev] Chaining try statements: eltry?

[Python-Dev] Chaining try statements: eltry? [Python-Dev] Chaining try statements: eltry?Guido van Rossum gvanrossum at gmail.com
Wed Jul 6 21:02:14 CEST 2005
On 7/6/05, Thomas Lotze <thomas at thomas-lotze.de> wrote:
> I want to ask what you think about introducing a keyword 'eltry' which
> would be the counterpart of 'elif' for try statements. This had been
> suggested before on python-list a couple of years ago by Jonathan
> Gardner, but nothing (that I could find) seems to have come of it.

I'm -1 on this. The use case doesn't occur often in my experience and
IMO putting each try statement in the else clause of the previous one
is a fine solution.

I also notice that your only example is very repetitive, and would be
better written as a loop, using Python's dynamic nature:

for decoder in foo_decode, bar_decode, foobar_decode:
    try:
        data = decoder(data)
        break
    except ValueError:
        print "data doesn't seem to be %s-encoded" % decoder.__name__

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4