What is wrapper.count += 1?

Screen Link: https://app.dataquest.io/m/414/decorators%3A-advanced/1/introduction

My Code:

def counter(func):
    def wrapper(*args, **kwargs):
        wrapper.count += 1
        # Call the function being decorated and return the result
        return func(*args,**kwargs)

    wrapper.count = 0
    # Return the new decorated function
    return wrapper
@counter
def foo():
    print('calling foo()')    

foo()
foo()

print('foo() was called {} times.'.format(foo.count))

Could you tell me what wrapper.count is in the wrapper function? What is a concept behind this?

This program counts how many times each function is called.

Thank you.

4 Likes

This is call function attributes. please check out these references

3 Likes

Thank you so much for your answer! I will look it up!

1 Like