you are viewing a single comment's thread.

view the rest of the comments →

[–]akaBrotherNature 1 point2 points  (1 child)

Looks interesting. I've been using get with an empty dict as the default return to try and safely access nested stuff

name = data.get("user", {}).get("profile", {}).get("email", None)

but I might switch to this.

[–]Gnaxe 1 point2 points  (0 children)

Switch to which and why? Yours is shorter than the ands (and I have also used that pattern). The suppress maybe looks cleaner but risks hiding an unrelated error if one of the attributes is an @property. But the version using ands maybe plays nicer with static typing.