def attrgetter(*items):
if len(items) == 1:
attr = items[0]
def g(obj):
return resolve_attr(obj, attr)
else:
def g(obj):
return tuple(resolve_attr(obj, attr) for attr in items)
return g
def resolve_attr(obj, attr):
for name in attr.split("."):
obj = getattr(obj, name)
return obj
1
lolizeppelin 2017-08-03 16:35:12 +08:00 via Android
g 是闭包
|
2
pppy OP @lolizeppelin 看错了 明白了 😝
|