import json
class Myclass():
def __init__(self):
with open("file_name.json", "r") as read_file:
data = json.load(read_file)
for key in data:
print key
key = getattr(self,'func_name')
def func_name(self,arg):
print "Pass"
obj = Myclass()
obj.func_name("test")
obj.key_from_file("test")
Output:
key_from_file
Pass
Traceback (most recent call last):
File "get_at.py", line 22, in <module>
obj.key_from_file("test")
AttributeError: Myclass instance has no attribute 'key_from_file'
I want to dynamically map all key in json file to func_name, so whenever we call obj.key_from_file("test") which should call obj.func_name("test")
How to do that ?