question

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‘]

 

时间: 2024-10-13 01:13:31

question的相关文章

是否通过技术任霆发够使肌肤

http://www.gome.com.cn/search?question=%E5%8F%B0%E5%B7%9E%E6%96%B0%E6%A1%A5%E9%95%87%e6%89%be%e5%b0%8f%e5%a7%90%e4%b8%8a%e9%97%a8%e6%9c%8d%e5%8a%a11858885v7572 http://www.gome.com.cn/search?question=%E5%8F%B0%E5%B7%9E%E6%96%B0%E6%A1%A5%E9%95%87%e6%89

榔举料昧卣pn5vu85bwh7a68krk

新华社瓦莱塔4月10日电(记者李拯宇 李佳)全国政协主席俞正声10日在前往非洲三国进行正式友好访问途中过境马耳他,在瓦莱塔会见马耳他议长法鲁贾. 俞正声说,中马保持长期友好关系,政治上相互信任,经济上密切合作,人文交流不断深化.中方感谢马方在中国撤侨行动中给予的支持和帮助.中方愿同马方一道,落实两国领导人达成的共识,弘扬中马传统友好,拓展在科技.渔业.旅游等领域互利合作,打造合作新亮点.中国全国政协愿与马耳他议会和社会各界保持密切交往,加强治国理政经验交流,为两国扩大务实合作营造良好环境,共同促

【Q&A】12C OCP 1z0-060 QUESTION 1: About Managing Temporary Tablespaces in a CDB

QUESTION 1 Your multitenant container (CDB) contains two pluggable databases (PDB), HR_PDB and ACCOUNTS_PDB, both of which use the CDB tablespace. The temp file is called temp01.tmp. A user issues a query on a table on one of the PDBs and receives th

nullcon HackIM 2016 -- Crypto Question 1

You are in this GAME. A critical mission, and you are surrounded by the beauties, ready to shed their slik gowns on your beck. On onside your feelings are pulling you apart and another side you are called by the duty. The biggiest question is seX OR

Question about of Softlayer IPSec

http://w3.insidepacket.net/index.php/16-softlayer-ipsec-4 Recently, one Softlayer customer complained that they have issue when the servers on the corporate network talk to VM guest on Softlayer.  They found that their VM guests in Softlayer always s

Chapter7: question 49 - 50

49. 把字符串转换为整数 很多细节需要注意.(空格,符号,溢出等) Go: 8. String to Integer (atoi) 50. 树种两个结点的最低公共祖先 A. 若是二叉搜索树,直接与根结点对比. 若都大于根节点,则在友子树:若都小于根节点,则在左子树:若根节点介于两数之间,则根节点即为答案. B. 普通树,若是孩子节点有指向父节点的指针,则问题变为求两个链表的第一个公共结点. 如:37题. C. 普通树:思路1,若一个结点的子树同时包含两个结点,而它的任一孩子结点的子树却不能同时

zoj 1763 A Simple Question of Chemistry

A Simple Question of Chemistry Time Limit: 2 Seconds      Memory Limit: 65536 KB Your chemistry lab instructor is a very enthusiastic graduate student who clearly has forgotten what their undergraduate Chemistry 101 lab experience was like. Your inst

Garena interview question

Web Developer Interview Anonymous Interview Candidate in Singapore (Singapore) No Offer Neutral Experience Difficult Interview Application I applied through an employee referral. The process took 5 days. I interviewed at Garena Online (Singapore (Sin

Chap6: question 46 - 48

46. 求 1+2+ - +n. 要求:不用乘除法.for.while.if.else.switch.case 以及条件判断语句(A?B:C). a. 利用构造函数求解 #include <iostream> using namespace std; class Sum{ public: Sum() {++n; sum += n;} static void reset() {sum = n = 0;} static int getSum(){ return sum;} private: sta

Chap5: question: 29 - 31

29. 数组中出现次数超过一半的数字. 方法a. 排序取中       O(nlogn). 方法b. partition 函数分割找中位数          >=O(n). 方法c. 设计数变量,扫描一遍.     O(n). #include <stdio.h> bool Invalid_Input = false; int getNumber(int data[], int length){ Invalid_Input = false; if(!data || length <