[Python-3000] Exception Expressions (original) (raw)

Jim Jewett jimjjewett at gmail.com
Fri Sep 1 16:24:42 CEST 2006


On 8/31/06, Brett Cannon <brett at python.org> wrote:

On 8/31/06, Calvin Spealman <ironfroggy at gmail.com> wrote: > On 8/31/06, Brett Cannon <brett at python.org> wrote: > > So this feels like the Perl idiom of using die: open(file) or die

> "Ouch" on the associated my idea with perl!

=) The truth hurts.

Isn't this almost the opposite of "or die"? Unless I'm having a very bad day, the die idiom is more like a SystemExit, but this proposal is a way to recover from expected Exceptions.

> func(ags) || die(msg)

means

>>> if not func(args):
...     raise SystemExit(msg)

This proposal, with the "a non-dict mapping might not have get" use case:

>>> ((mymap[k] except KeyError then default) for key in source)

means

>>> def __temp():
...     for element in source:
...         try:
...             v=mymap[k]
...         except KeyError:
...             v=default
...         yield v
>>> __temp()

-jJ



More information about the Python-3000 mailing list