Quick actions

cmd+k|ctrl+k

Navigation

Languages

Python Decorators: decorate recursive function (weird version)

Snippet info

Language

Python

Visibility

public

Author

atymo

Created

2018-09-24T12:49:42Z

Updated

2018-10-25T09:25:52Z

def dec(f):
    def wrapper(*argv):
        print('Arguments got:', argv, 'Decorated!')
        return(f(*argv))
    return(wrapper)

def f(n):
    print(n, 'Original!')
    if n == 1: return(1)
    else: return(f(n - 1) + n)

print("first example - original function")
print(f(5))

dec_f = dec(f)
print("second example")
print(dec_f(5))

f = dec(f)
print("third example")
print(f(5))
INFO