0

I need to call the function notice twice. And here notice function calls a decorator.

def decorator(func):
    def wrapper(*args, **kwargs):
        # print 'first' or 'second' here.
        return func(*args, **kwargs)
    return wrapper


@decorator
def notice():
    print("call")


notice()
notice()

Here what I would like to print is

first call
second call

Is it possible?

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
haojie
  • 593
  • 1
  • 7
  • 19
  • 1
    @Tomerikoo Yes, this is the answer I am looking for. https://stackoverflow.com/a/21717396/10844937 – haojie Apr 03 '23 at 13:18
  • `notice` does not call the decorator. The decorator creates a new function that wraps the original `notice` function and binds that to the name `notice`. (The decorator is called *on* the original function, as if you had written `notice = decorator(notice)`.) – chepner Apr 03 '23 at 13:24

0 Answers0