I have a class as follows:
class Filter(object):
def __init__(self):
self._alphabet_digits = (
"abc|def|ghc" # alphabet
"|"
"123|456|789|000" # digits
)
self._mixed = "123abc|456def" # digits and alphabet
def filter_decorate(func):
def filter_out(cls, line):
return bool(re.search(func(cls, line)))
return filter_out
@property
def alphabet_digits(self):
return self._alphabet_digits
@property
def mixed(self):
return self._mixed
@classmethod
@filter_decorate
def out_alphabet_digits(cls, line):
return cls.alphabet_digits, line
@classmethod
@filter_decorate
def out_mixed(cls, line):
return cls.mixed, line
I got the following error while trying:
filter = Filter()
filter.out_alphabet_digits("123 aflk l 32")
AttributeError: type object 'Filter' has no attribute 'out_alphabet_digists'
I know that the attribute is bounded to the instance filter
but in a classmethod I should use cls
as the first argument.. And after I change every cls
to self
I get a similar error. How can I use classmethod and one self-created decorator together?