您好,登錄后才能下訂單哦!
import time
def timmer(func): # 這就是裝飾器!
def warpper(*args,*kwargs):
start_time = time.time()
func(args,**kwargs)
stop_time = time.time()
print("the func run time is %s" % (stop_time - start_time))
return warpper
@timmer #函數的內存地址賦予(把timmer這個裝飾器的內存地址給調用他的函數)
def test():
time.sleep(3)
print("test1")
test()
#1
def fff():
print("llllllll")
xxx()
def xxx():
print("ccococococ")
fff()
#2
def xxx():
print("ccococococ")
def fff():
print("llllllll")
xxx()
fff()
#3 調用xxx的時候后,xxx沒有先定義!
def fff():
print("llllllll")
xxx()
fff()
def xxx():
print("ccococococ")
def timmer(func): # 這就是裝飾器!
def warpper():
start_time = time.time()
func()
stop_time = time.time()
print("the func run time is %s" % (stop_time - start_time))
return warpper
def test():
time.sleep(3)
print("test1")
timmer(test)
def timmer(func): # 這就是裝飾器!
def warpper():
start_time = time.time()
func()
stop_time = time.time()
print("the func run time is %s" % (stop_time - start_time))
return warpper
@timmer #函數的內存地址賦予(把timmer這個裝飾器的內存地址給調用他的函數)
def test():
time.sleep(3)
print("test1")
test()
def timmer(func): # 這就是裝飾器!
def warpper(*args,*kwargs):
start_time = time.time()
func(args,**kwargs)
stop_time = time.time()
print("the func run time is %s" % (stop_time - start_time))
return warpper
@timmer #函數的內存地址賦予(把timmer這個裝飾器的內存地址給調用他的函數)
def test(): # @timmer=test
time.sleep(3)
print("test1")
test("alex")
user,keypass="hy","123"
def xxxx(func):
def wapper(*args, *kwargs):
username = input("username:").strip()
pasword = input("pssword:").strip()
if user == username and keypass == pasword:
print("welcome to logging---。。。。")
rrs = func(args, **kwargs)
return rrs
else:
print("username or passord is no")
return wapper
def index():
print("welcome to index")
return 0@xxxx
br/>@xxxx
print("welcome to home ")
return "alex is pig " # 函數的返回值需要輸出,home()調用不會輸出返回值。@xxxx
br/>@xxxx
print("welcome to bbs")
index()
print(home())
bbs()
user,passwd="alex","123"
def auth(aupe):
def out_warpper(func):
def wrapper(*args, *kwargs):
if aupe == "local":
username = input("username:").strip()
password = input("password:").strip()
if user == username and passwd == password:
print("\033[32;1muser has passed authentication\033[0m")
res = func(args, **kwargs)
return res
else:
print("\033[32;1mInvalid username or password\033[0m")
elif aupe == "country":
print("搞毛線ldap,不會")
else:print("city 歡迎你")
return wrapper
return out_warpper@auth(aupe="city")
br/>@auth(aupe="city")
print("welcome to city!")@auth(aupe="country")
br/>@auth(aupe="country")
print("welcome to country!!")@auth(aupe="local")
br/>@auth(aupe="local")
print("welcome to home!!! %name")
acct=acc-name
return "from there",acct
city()
country()
local()
print(local())# 函數的返回值需要print函數的調用(local()),或者賦值給一個變量,輸出那個變量!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。