[Python-ideas] "else" expression ":"

Philipp A. flying-sheep at web.de
Thu Apr 18 16:21:06 CEST 2013


no, this is different; it’s not for booleans, but for assertions, and could
be used for e.g. exhaustive switches, e.g. it would make the first test in
the following unnecessary:

if spam not in {"a", "b", "c"}:
    throw new ValueError("spam {} should be a, b, or c!".format(spam))
if spam == "a":
    foo()
elif spam == "b":
    bar()
else:
    baz()

i’m not saing i support the idea though. i’d rather see scala-like
extensible pattern matching. that would solve this, the eternal switch
debate, and more (using extractors).

is there a proposal for pattern matching? if not, i’ll come up with one ;)


2013/4/18 Yaroslav Fedevych <yaroslav at fedevych.name>

> An obligatory read for anyone who comes up with ideas like this:
> http://thedailywtf.com/Articles/ButAnything-Can-Happen!.aspx
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130418/e7424d97/attachment.html>


More information about the Python-ideas mailing list