First page Back Continue Last page Overview Graphics

Decorator with Parameter

We have to wrap another function around our previous decorator function to accomplish this. We can now easy say "Good Morning" in the Greek way:

def greeting(expr):

def greeting_decorator(func):

def function_wrapper(x):

print(expr + ", " + func.__name__ + " returns:")

func(x)

return function_wrapper

return greeting_decorator

@greeting("καλημερα")

def foo(x):

print(42)

foo("Hi")

καλημερα, foo returns:

42