Quick actions

cmd+k|ctrl+k

Navigation

Languages

Python Decorators: Class as a decorator

Snippet info

Language

Python

Visibility

public

Author

atymo

Created

2018-05-13T13:02:11Z

Updated

2018-05-13T13:02:11Z

class entry_exit(object):

    def __init__(self, f):
        self.f = f

    def __call__(self):
        print("Entering", self.f.__name__)
        self.f()
        print("Exited", self.f.__name__)

@entry_exit
def func1():
    print("inside func1()")

@entry_exit
def func2():
    print("inside func2()")

func1()
func2()
INFO