Decorator

@hoge Someone like

def poko(func):
	print "poko"
	return "poko_string"

@poko
def hoge():
	pass

so

def hoge():
	pass
hoge = poko(hoge)

Same as. Actually, you can use functool's wraps function

from functools import wraps

def poko(func):
	@wraps(func)
	def wrapper(*args, **kwargs):
		"""Actions you want to add""""
		# do pokopoko
		#add hoge hoge
		return func(*args, **kwargs)
	return wrapper

@poko
def hoge():
	pass

like

Recommended Posts

Decorator 1
Decorator
Decorator
MyHDL decorator
Decorator to retry
Design Pattern #Decorator
Python function decorator
Write decorator in class
python decorator to retry
Make a function decorator
Summarize Python's @property decorator
python decorator usage notes
Use a Property Decorator?
Python decorator operation memo
I tried Python> decorator
Decorate with a decorator