'How to get in a superclass full names of all methods in subclasses that start with the same two letters in python
I have number of subclasses all of which have number of methods whose names start with "on.." eg.:
def on_index(self):
raise NotImplementedError()
def on_spiking_intent(self):
raise NotImplementedError()
def on_no_option(self):
raise NotImplementedError()
I would like to write a method in the superclass which prints a list of all the "on..." methods of its subclasses and specifies to which subclass the method belongs.
I guess this get_all_on_methods method need not be in the superclass, but it made sense to me to put it there as only the superclass unites the subclasses.
How should I go about this? I was thinking about somehow using decorators like putting
@onmethod
in front of every "on..." method or also somehow using an abstract class. But I actually don't know.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|