0

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?

2
  • Yes you are right it is an XY problem now that you mentioned it became clear that i can't do the problem like this. Commented Jan 28, 2022 at 6:28
  • @j1-lee I want to associate the strings in the list to FOAF.string_name so that it will perform that FOAF thing on my string_name Commented Jan 28, 2022 at 6:33

2 Answers 2

1

you could achive something similar like this :

obj = FOAF
for i in methods: 
   getattr(obj, i)() # <-- this will call the needed method

Good luck :)

Sign up to request clarification or add additional context in comments.

Comments

0

This is an oneliner way:

methods = ['plays', 'plays', 'is', 'is']
relation_dict = {method: getattr(FOAF, method) for method in methods}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.