This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients brett.cannon, serhiy.storchaka, zach.ware
Date 2012-12-16.11:29:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Here is a functional (and more effective) equivalent of attrgetter:

def attrgetter(attr, *attrs):
    Return a callable object that fetches the given attribute(s) from its operand.
    After f=attrgetter('name'), the call f(r) returns
    After g=attrgetter('name', 'date'), the call g(r) returns (,
    After h=attrgetter('name.first', 'name.last'), the call h(r) returns
    if not attrs:
        if not isinstance(attr, str):
            raise TypeError('attribute name must be a string')
        names = attr.split('.')
        def func(obj):
            for name in names:
                obj = getattr(obj, name)
            return obj
        return func
        getters = tuple(map(attrgetter, (attr,) + attrs))
        def func(obj):
            return tuple(getter(obj) for getter in getters)
        return func
Date User Action Args
2012-12-16 11:29:26serhiy.storchakasetrecipients: + serhiy.storchaka, brett.cannon, zach.ware
2012-12-16 11:29:26serhiy.storchakasetmessageid: <>
2012-12-16 11:29:26serhiy.storchakalinkissue16694 messages
2012-12-16 11:29:26serhiy.storchakacreate