[Python-ideas] PEP 505: None-aware operators

Michael Selik mike at selik.org
Thu Jul 19 20:57:50 EDT 2018


On Thu, Jul 19, 2018 at 8:40 PM Michael Lee <michael.lee.0x2a at gmail.com>
wrote:

>
>    1. ...
>
>    2. We can already easily get the same functionality using standard
>    Python. E.g., instead of doing foo?["bar"]?[0]?["baz"], we could do lookup(foo,
>    "bar", 0, "baz") where lookup is a function that looks roughly like
>    this:
>
>        def lookup(item, *parts):
>            for part in parts:
>                if item is None:
>                    return None
>                item = item[parts]
>            return item
>
>
Try/except also looks decent.

    try:
        x = foo['bar'][0]
    except TypeError:
        x = 'default'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180719/92841f15/attachment.html>


More information about the Python-ideas mailing list