chained attrgetter

Alexey Borzenkov snaury at gmail.com
Wed Oct 25 17:03:22 EDT 2006


On Oct 25, 10:00 pm, "David S." <davidsch... at alumni.tufts.edu> wrote:
> Does something like operator.getattr exist to perform a chained attr
> lookup?

Do you mean something like

class cattrgetter:
    def __init__(self, name):
        self.names = name.split('.')
    def __call__(self, obj):
        for name in self.names:
            obj = getattr(obj, name)
        return obj

?




More information about the Python-list mailing list