1.config Module
1 ImportConfigparser2 3conf =Configparser. Configparser ()4conf["DEFAULT"] = {'Serveraliveinterval':' $',5 'Compression':'Yes',6 'CompressionLevel':'9'}7conf['wwwwwwwww'] = {}8conf['wwwwwwwww']['User'] ='Baidu'9conf['topsecret.server.com'] = {}TenTopsecret = conf['topsecret.server.com'] onetopsecret['Host Port'] ='50022' aWith open ('Conf.ini','W') as F: -F.write (conf)
2.hashlib operation
1 Import HMAC 2 h = hmac.new (b'hsc')3 h.update (b'12233 ' )4print(h)
3.random Module
1 ImportRandom2 Print(random.random ())3 Print(random.randint)#0,1,2 Random4 Print(random.randrange)#0,1 Random5 6Checkcode ="'7 forIinchRange (6):8Current = Random.randrange (0,6)9 ifcurrent! =I:Tentemp = CHR (random.randint (65,90)) one Else: atemp = Random.randint (0,9) -Checkcode + =Str (temp) - Print(checkcode)
4.shelve Module
1 Importshelve2 3D = Shelve.open ('shelve_test')4 5 defStu_data (name,age):6 Print("Register Stu", Name,age)7name = ["HSC","XJP","ABM"]8info = {"name":"HSC"," age": 18}9 Tend["Test"] =name oned["Info"] =Info ad['func'] = Stu_data
5.shutil Module
1 ImportShutil2 3 #f1 = open ("random mod. Py")4 #F2 = open ("random_new. py", ' W ')5 #shutil.copyfileobj (f1,f2)6 7 #shutil.copyfile ("notes", R ' d:\123 ')8Shutil.make_archive ('www','Gztar', Root_dir=r'C:\Users\heshaochuan\PycharmProjects\py_s15\day6')
6. Logging Module
1 ImportLogging2 3Log_test = Logging.getlogger ('TEST')4Logging.basicconfig (filename='Wwwwwwwwww.log', level=Logging.info)5Logging.debug ('Mthgh')6Logging.info ('2131234324')
7.re Module
Common Regular Expression symbols
| 123456789101112131415161718192021 |
‘.‘默认匹配除\n之外的任意一个字符,若指定flag DOTALL,则匹配任意字符,包括换行‘^‘匹配字符开头,若指定flags MULTILINE,这种也可以匹配上(r"^a","\nabc\neee",flags=re.MULTILINE)‘$‘匹配字符结尾,或e.search("foo$","bfoo\nsdfsf",flags=re.MULTILINE).group()也可以‘*‘匹配*号前的字符0次或多次,re.findall("ab*","cabb3abcbbac") 结果为[‘abb‘, ‘ab‘, ‘a‘]‘+‘ 匹配前一个字符1次或多次,re.findall("ab+","ab+cd+abb+bba") 结果[‘ab‘, ‘abb‘]‘?‘匹配前一个字符1次或0次‘{m}‘ 匹配前一个字符m次‘{n,m}‘匹配前一个字符n到m次,re.findall("ab{1,3}","abb abc abbcbbb") 结果‘abb‘, ‘ab‘, ‘abb‘]‘|‘匹配|左或|右的字符,re.search("abc|ABC","ABCBabcCD").group() 结果‘ABC‘‘(...)‘分组匹配,re.search("(abc){2}a(123|456)c", "abcabca456c").group() 结果 abcabca456c‘\A‘只从字符开头匹配,re.search("\Aabc","alexabc") 是匹配不到的‘\Z‘匹配字符结尾,同$‘\d‘匹配数字0-9‘\D‘匹配非数字‘\w‘匹配[A-Za-z0-9]‘\W‘匹配非[A-Za-z0-9]‘s‘匹配空白字符、\t、\n、\r , re.search("\s+","ab\tc1\n3").group() 结果 ‘\t‘‘(?P<name>...)‘分组匹配 re.search("(?P<province>[0-9]{4})(?P<city>[0-9]{2})(?P<birthday>[0-9]{4})","371481199306143242").groupdict("city") 结果{‘province‘: ‘3714‘, ‘city‘: ‘81‘, ‘birthday‘: ‘1993‘} |
Python road, Day6-python Foundation