Skip to content

Instantly share code, notes, and snippets.

@JackInTaiwan
Created November 3, 2018 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JackInTaiwan/41ded88d4c8c13c53c56f4455534e71b to your computer and use it in GitHub Desktop.
Save JackInTaiwan/41ded88d4c8c13c53c56f4455534e71b to your computer and use it in GitHub Desktop.
def print_func_name(func):
def warp_1():
print("Now use function '{}'".format(func.__name__))
func()
return warp_1
def print_time(func):
import time
def warp_2():
print("Now the Unix time is {}".format(int(time.time())))
func()
return warp_2
@print_func_name
@print_time
def dog_bark():
print("Bark !!!")
@print_time
@print_func_name
def cat_miaow():
print("Miaow !!!")
if __name__ == "__main__":
dog_bark()
# > Now use function 'warp_2'
# > Now the Unix time is 1541239747
# > Bark !!!
cat_miaow()
# > Now the Unix time is 1541239747
# > Now use function 'cat_miaow'
# > Miaow !!!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment