Folgen

Ist there really no nice way to access nested Dicts in Python (if one of the intermediate Dicts might be None)?

Ended up with some sort of safeget(data, *keys) to return none if one of the Dicts actually turns out to be None.

@RyunoKi Yeah, possible. But not nice if you need to do it a lot of times, you would still need to wrap it on a function.

@v0tti
As far as I know, functions aren't that performant in Python.

Perhaps worth to encapsulate it as a class instead.

This way, you can abstract away the internals.

@v0tti What about chaining lots of baz.get('foo', {}).get('bar', {})?

@sophie This will explode if foo actually is None. It only returns {} if it does not exist.

@v0tti @sophie

((baz.get("foo") or {}).get("bar") or {})

but it doesn't get less ugly xD

Melde dich an, um an der Konversation teilzuhaben
fem.social

Eine Mastodon-Instanz gehostet im Thüringer Wald von FeM e.V.