Ad
Code
Diff
  • from functools import wraps
    
    
    def greetings(func):
        @wraps(func)
        def inner(*args, **kwargs):
            return f'Hello, {func(*args, **kwargs)}!'
        return inner
    
    
    @greetings
    def world():
        return "world"
    
    
    # world()
    
    • class Greetings(object):
    • from functools import wraps
    • def __init__(self, the_greeter):
    • self.the_greeter = the_greeter
    • def __call__(self, *args, **kwargs):
    • return '{} World'.format(self.the_greeter.__name__)
    • def greetings(func):
    • @wraps(func)
    • def inner(*args, **kwargs):
    • return f'Hello, {func(*args, **kwargs)}!'
    • return inner
    • @Greetings
    • def Hello():
    • pass
    • # Hello()
    • @greetings
    • def world():
    • return "world"
    • # world()