I'm trying add new methods dynamically in python in the constructor ...
Context
I wrote a Python module in C++ that interacts with my signal processing libraries written in C ... I have generic method to access my modules (called filters) parameters.
Eg.:
int my_filter_set( void * filter_handle, const char * method_id, void * p_arg );
So my cpython wraps it like this :
filter.set(method_id,value)
And I have access to all my method ids.
>>> filter.setters
['SampleRate','...']
Goal
I would like to generate setters like :
>>> filter.setSampleRate(value)
in a derived class.
class Filter(BaseFilter):
'''
classdocs
'''
def __init__(self, name, library):
'''
Constructor
'''
BaseFilter.__init__(self,name,library)
for setter_id in self.setters:
code = 'self.set(' + setter_id + ',value)'
# @todo add the method body to a new method called 'set' + method_id (with 'value' as argument)
Questions are ...
- Is it possible ?
- With python types module ?
- How to do it ?
I already checked this but I don't see the way I can adapt it to my purpose.
Thanks.