python decorator @mydecorator

 

The follow code demonstrate decorator in python. When executed, the closest function / decorator will be executed first and the the one above it. 

As a result, you will get <c><b><a>hello world</a></b></c>


def dec1(a: callable):
    def inner():
      x = a()
      return "<a>" + x + "</a>"
    return inner

def dec2(a: callable):
   
    def inner():
      x = a()
      return "<b>" + a() + "</b>"
    return inner

def dec3(a: callable):
   
    def inner():
      x = a()
      return "<c>" + a() + "</c>"
    return inner


@dec3
@dec2
@dec1
def hello():
    return "hello world"


Comments

Popular posts from this blog

The specified initialization vector (IV) does not match the block size for this algorithm