July 20, 2018
12:57 a.m.
On Thu, Jul 19, 2018 at 8:40 PM Michael Lee <michael.lee.0x2a@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'