Jan-01-2024, 07:30 AM
hi
the below code is in address:
https://python101.pythonlibrary.org/chap...ators.html
1)what is the klass argument in def class_tripler(klass, x)? if I write decor.class_tripler('test',3), causes a TypeError error message, but the method has two arguments.
2) On the same page is written that
thanks
the below code is in address:
https://python101.pythonlibrary.org/chap...ators.html
# decorator in python: @staticmethod & @classmethod usage # from address:https://python101.pythonlibrary.org/chapter25_decorators.html class DecoratorTest(object): """ Test regular method vs @classmethod vs @staticmethod """ def __init__(self): """Constructor""" pass def doubler(self, x): """""" print("running doubler") return x*2 @classmethod def class_tripler(klass, x): """""" print("running tripler: %s" % klass) return x*3 @staticmethod def static_quad(x): """""" print("running quad") return x*4 if __name__ == "__main__": decor = DecoratorTest() print(f"decor.doubler(5) results: {decor.doubler(5)}" ) print("-"*50) print(f"decor.class_tripler(3) results: {decor.class_tripler(3)}") print("-"*50) print(f"DecoratorTest.class_tripler(3) results:{DecoratorTest.class_tripler(3)}" ) print("-"*50) print(f"DecoratorTest.static_quad(2) results: {DecoratorTest.static_quad(2)}") print("-"*50) print(f"decor.static_quad(3) results: {decor.static_quad(3)}") print("-"*50) print("-"*50) print("-"*50) print(f"decor.doubler results: {decor.doubler}") print("-"*50) print(f"decor.class_tripler results: {decor.class_tripler}") print("-"*50) print(f"decor.static_quad results: {decor.static_quad}") print("-"*50)my questions :
1)what is the klass argument in def class_tripler(klass, x)? if I write decor.class_tripler('test',3), causes a TypeError error message, but the method has two arguments.
2) On the same page is written that
Quote:You will also note that the last print statement shows that decor.static_quad returns a regular function instead of a bound method.. what are the meanings of regular function and bound function?
thanks