how construct method name use instantiated class? i'm trying run method in class 'jsonmaker' method corresponds datatype specified in filein string.
for filein in filein_list: datatype = filein[(filein.find('_')):-8] method_name = pjoin(datatype + 'populate') instantiated_class.method_name(arg1, arg2, arg3)
when try above code error message
'attributeerror: 'jsonmaker' object has no attribute 'method_name''
there in fact method in jsonmaker matches pjoin(datatype + 'populate') how tell class recognize that? sorry if i'm not explaining well.
you can't reference attribute of class instance putting variable directly behind dot reference. not when variable references string same name of attribute.
you instead use getattr
method
string , call parameters:
getattr(instantiated_class, method_name)(arg1, arg2, arg3)
Comments
Post a Comment