Python/Decorator: Difference between revisions

From Fundamental Ramen
Jump to navigation Jump to search
(Created page with "<source lang="python"> def pre_hook(func): def wrapper(*args): a = args[0] + 1 b = args[1] + 1 return func(a, b) return wrapper </source> <sou...")
 
No edit summary
Line 1: Line 1:
{| class="wikitable"
! TODO || Code
|-
|
|
<source lang="python">
<source lang="python">
def pre_hook(func):
def pre_hook(func):
Line 7: Line 12:
     return wrapper
     return wrapper
</source>
</source>
 
|-
|
|
<source lang="python">
<source lang="python">
def post_hook(func):
def post_hook(func):
Line 14: Line 21:
     return wrapper
     return wrapper
</source>
</source>
 
|-
|
|
<source lang="python">
<source lang="python">
def duo_hook(func):
def duo_hook(func):
Line 25: Line 34:
     return wrapper
     return wrapper
</source>
</source>
|}

Revision as of 04:01, 13 June 2019

TODO Code
def pre_hook(func):
    def wrapper(*args):
        a = args[0] + 1
        b = args[1] + 1
        return func(a, b)
    return wrapper
def post_hook(func):
    def wrapper(*args):
        print(func(*args))
    return wrapper
def duo_hook(func):
    def wrapper(*args):
        a = args[0] + 1
        b = args[1] + 1
        sum = func(a, b)
        print(sum)
        return sum
    return wrapper