@ Introducing Python: Modern Computing in Simple Packages by Bill Lubanovic (No. 2777 / 12833)
Il semble y avoir une fonction appelée décorateur.
J'ai essayé.
http://ideone.com/6rPiXX
def decorate_it(func):
def new_function(*args, **kwargs):
print('***MAY I HAVE YOUR ATTENTION, PLEASE***')
print('This is 7of9, Tertiary Adjunct of Unimatrix Zero One.')
print('I have something to tell you, today')
result = func(*args, **kwargs)
print('Thank you for your attention')
print('Have a good day')
print('By the way, your aunt has often told me that ...')
return result
return new_function
def say_hello(word):
print(word)
@decorate_it
def say_decorated(word):
print(word)
say_hello('Nice to meet you')
say_decorated('Nice seeing you')
run
Success time: 0.01 memory: 28384 signal:0
Nice to meet you
***MAY I HAVE YOUR ATTENTION, PLEASE***
This is 7of9, Tertiary Adjunct of Unimatrix Zero One.
I have something to tell you, today
Nice seeing you
Thank you for your attention
Have a good day
By the way, your aunt has often told me that ...
Recommended Posts