码迷,mamicode.com
首页 > 其他好文 > 详细

question

时间:2017-07-28 22:08:36      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:bsp   deepcopy   border   else   return   列表   执行   otto   sse   

1、带参数的装饰器执行过程的跳转很晕,设置了断点一步一步执行,仍不清楚执行步骤

 1 #本地验证
 2 user,passwd = "abc","123"
 3  
 4 def auth(auth_type):  
 5     print("auth func:",auth_type)
 6     def outer_wrapper(func):   
 7         def wrapper(*args,**kwargs):  
 8             print("wrapper func args:",*args,**kwargs)
 9             username = input("Username:").strip()
10             password = input("Password:").strip()
11             if auth_type == "local":
12                 if user == username and passwd == password:
13                     print("\033[32mUser has passed authentication\033[0m")
14                     res = func(*args,**kwargs)
15                     print("--after authentication")
16                     return res
17                 else:
18                     exit("Invalid username or password")
19             elif auth_type == "ldap":
20                 pass
21         return wrapper
22     return outer_wrapper
23  
24 def index():
25     print("welcome to index page")
26  
27 @auth(auth_type="local")  #带参数装饰器
28 def home():
29     print("welcome to home page")
30     return "from home"
31  
32 @auth(auth_type="ldap")   #带参数装饰器
33 def bbs():
34     print("welcome  to bbs page")
35  
36 index()
37 home()
38 bbs()

2、列表、元组、字典中的深copy、浅copy如何理解?

import copy
name1 = [a,b,[m,n],c]
name2 = copy.copy(name1)
name3 = copy.deepcopy(name1)
print(name1)
print(name2)
print(name3)

name1[0] = h
name1[2][0] = M
print(name1)
print(name2)
print(name3)
结果:
[a, b, [m, n], c]
[a, b, [m, n], c]

[h, b, [M, n], c]
[a, b, [M, n], c]
[a, b, [m, n], c]

 

 

 

question

标签:bsp   deepcopy   border   else   return   列表   执行   otto   sse   

原文地址:http://www.cnblogs.com/wengxq/p/7252492.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!