Decorator in Python
from decorator import display
@display
def decorator_example():
import decorator
decorator.with_param("danny")
print("")
decorator.without_param("danny")
@display
def mixin_example():
import mixin
# When changing the Dog[int, int] to Dog[str, int],
# call(). will show the string function
A = mixin.Ann("danny").call()
K = mixin.Ken(1).call()
print(A.capitalize())
# print(K.bit_length())
decorator_example()
# mixin_example()
from decorator import display
@display
def decorator_example():
import decorator
decorator.with_param("danny")
print("")
decorator.without_param("danny")
decorator_example()
def logged(func):
def with_logging(*args, **kwargs):
print(func.__name__ + " was called")
return func(*args, **kwargs)
return with_logging
def logged_param(x):
def logged(func):
print(x)
def with_logging(*args, **kwargs):
print(func.__name__ + " was called")
return func(*args, **kwargs)
return with_logging
return logged
@logged_param("danny1")
def p(x):
print(x)
pass
p("danny") # i.e. logged_param("danny1")(p)('danny')