Reputation: 243
I have a list of methods which I have to execute on an Object. These are the methods
methods = ['plays', 'plays', 'is', 'is']
relation_dict = {}
I want to get a relation dictionary which looks like this
relation_dict = {'plays':FOAF.plays,'plays':FOAF.plays, 'is':FOAF.is, 'is':FOAF.is}
here FOAF
is the object. How can we do this?
Upvotes: 0
Views: 56
Reputation: 248
This is an oneliner way:
methods = ['plays', 'plays', 'is', 'is']
relation_dict = {method: getattr(FOAF, method) for method in methods}
Upvotes: 0
Reputation: 859
you could achive something similar like this :
obj = FOAF
for i in methods:
getattr(obj, i)() # <-- this will call the needed method
Good luck :)
Upvotes: 1