You could probably do this by extending operator.attrgetter() to take anOn Oct 27, 2016, at 06:27 PM, Joonas Liik wrote:
>perhaps just having a utility function can get us some of the way there..
>r = a.b.x.z
># will default to None
>r = a?.b?.x?.z
>r = get_null_aware(a, "b.x.z") # long but no new syntax, can be
optional 'coalesce' keyword. It wouldn't be super pretty, but it has the
advantage of no magical new syntax. E.g. your example would be:
from operator import attrgetter
r = attrgetter('b.x.z', coalesce=True)
That might be good enough for honestly how rare I think this use case is.
(Similarly with itemgetter().)
Python-ideas mailing list
Code of Conduct: http://python.org/psf/