Issue
Construction getattr(obj, 'attr1.attr2', None)
does not work.
What are the best practices to replace this construction?
Divide that into two getattr statements?
Solution
You can use operator.attrgetter()
in order to get multiple attributes at once:
from operator import attrgetter
my_attrs = attrgetter(attr1, attr2)(obj)
Answered By - Mazdak
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.