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/2006-June/066254.html below:

[Python-Dev] Switch statement

[Python-Dev] Switch statement [Python-Dev] Switch statementDelaney, Timothy (Tim) tdelaney at avaya.com
Mon Jun 19 23:40:10 CEST 2006
Guido van Rossum wrote:

> I wonder if there should be two default clauses, or some other
> syntactic way to indicate whether we expect all x to be hashable?

    switch expr:
        case 1:
            statements
        case 2:
            statements
        else:
            statements
        except KeyError:
            statements
        finally:
            statements

    switch expr:
        case 1:
            statements
        case 2:
            statements
        else:
            statements
    except KeyError:
        statements
    finally:
        statements

:)

Seriously, I think I'd rather be explicit and just have KeyError
propagate. If someone is expecting occasional unhashable values, they
can just wrap it in try/except.

    try:
        switch expr:
            case 1:
                statements
            case 2:
                statements
            else:
                statements
    except KeyError:
        statements
    finally:
        statements

The first syntax though does have the advantage that it could catch only
KeyErrors raised from the switch statement. That could be easily handled
by a separate SwitchKeyError exception (inheriting from KeyError).

Tim Delaney
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