I'm refactoring some code, and I thought I could use a bit of Reflection! So, I have this for now:
def f(self, clazz):
[...]
boolean = False
if hasattr(clazz_instace, 'some_attribute'):
setattr(clazz_instace, 'some_attribute', True)
boolean = True
if boolean:
result = getattr(clazz_instace, 'another_method')(None, request=request)
return result['objects']
sorted_objects = getattr(clazz_instace, 'One_more_method')(request)
result = getattr(clazz_instace, 'another_method')(sorted_objects, request=request)
return [...]
My question is about the strings I used to indicate which method I'm searching for regarding to the clazz_instance. I'd like to know if there's another and very best way to do what I did (In a dinamic way to be specific)? I mean, intead of putting method's name like strings directly as I did, would be really nice if I could verify dinamically those methods, differently.
Could you give some nice ideas? How would you do it?
Thanks in advance!!!