Quick actions

cmd+k|ctrl+k

Navigation

Languages

Python Decorators: Basic Decorator

Snippet info

Language

Python

Visibility

public

Author

atymo

Created

2018-05-13T11:37:52Z

Updated

2018-07-20T11:39:47Z

def mydecorator(decorated_func):
    def wrapped(*args, **kwargs):
        print("Something happened in decorator!")
        return decorated_func(*args, **kwargs)
    return wrapped

@mydecorator
def myfunc(myarg):
    print("my function", myarg)
    
def mysecond_func(myarg):
    print("my second function", myarg)

myfunc('for the Talk')
mysecond_func = mydecorator(mysecond_func)
mysecond_func('is doing the same')
INFO