import amara
def chain_attribute_call(obj, attlist):
"""
Allows to execute chain attribute calls
"""
splitted_attrs = attlist.split(".")
current_dom = obj
for attr in splitted_attrs:
current_dom = getattr(current_dom, attr)
return current_dom
doc = amara.parse("sample.xml")
print chain_attribute_call(doc, "X.Y.Z")
In oder to execute chain attribute calls for an object as a string, I had to develop the clumsy snippet above. I am curious if there would be a more clever / efficient solution to this.
you could also use:
from operator import attrgetter
attrgetter('x.y.z')(doc)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With