I want to do a generic class in Python with one method
I know that without metaclasses will not do, but I do not know how to apply them :)
something like this:
class GenericClass:
attr_a = ''
attr_b = ''
def count(text):
return len(text)/attr_a + attr_b
class A(GenericClass):
attr_a = 2
attr_b = 1
text = "Hello, I'm under the water"
print(A.count(text))
# 14
Defining count
as a class method would make that work:
@classmethod
def count(cls, text):
return len(text) / cls.attr_a + cls.attr_b