0

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?

Lerner Zhang
  • 6,184
  • 2
  • 49
  • 66
  • pls check the name function name..........`digists != digits` – Avinash Raj Sep 21 '16 at 08:02
  • @AvinashRaj is right, you are trying to `out_alphabet_digiSTS` and you got `out_alphabet_digiTS` – vishes_shell Sep 21 '16 at 08:04
  • @AvinashRaj Sorry a typo. I'll improve my code and description later since it's just a mess from my own perspective. – Lerner Zhang Sep 21 '16 at 08:04
  • Possible duplicate of [Decorating python class methods, how do I pass the instance to the decorator?](http://stackoverflow.com/questions/2365701/decorating-python-class-methods-how-do-i-pass-the-instance-to-the-decorator) – aneroid Sep 21 '16 at 08:07

0 Answers0