一鼓作气 博客--第六篇 note6
生活随笔
收集整理的這篇文章主要介紹了
一鼓作气 博客--第六篇 note6
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、無論公司付給你多少,你的青春都是廉價的!!2、通往財富自由之路 --得到APP3、time3.1 time.time()t = time.time()print(t) #--->1479138541.484613.2time.asctime()f = time.asctime()print(f) #---->Mon Nov 14 23:49:01 20163.3 time.localtime()l = time.localtime()print(l)3.4時間的加減l = time.localtime()print(l)g = time.localtime(time.time()-600)print(g)m = time.mktime(time.localtime())print(m)k = time.strptime('2014-11-02','%Y-%m-%d')print(k)p= time.strftime('%Y-%m-%d')print(p) ##默認當前時間print(time.strftime('%Y-%m-%d',time.localtime()))
rule1 = 'abc'
pattern = re.compile(r'hello')
args = 'hello world! where is abcd'
res = re.search(pattern, args)
if res:
res = res.group()
print('result:%s'%res)#
?
lshutil.copycopyfiletarimport tarfiledes = tarfile.open(r'D:\BaiduYunDownload\1114.zip','w')des.add(r'D:\BaiduYunDownload\day2_homework\day2_homework\three_menu',arcname='hbai')des.close()shelv***過濾文件:shutil.copytree(r'D:\py15\py15_day1','test',ignore=shutil.ignore_patterns('*.md'))??這樣可以過濾文件?XML修改刪除:config parser紙打印自己和默認的hashlibimport hashlibm = hashlib.md5(b'alex123')print(m.hexdigest())m1=hashlib.md5()m1.update(b'alex')m1.update(b'123') ##追加print(m1.hexdigest())hmac日志級別 不輸出某些級別 logPython 自帶了re模塊,它提供了對正則表達式的支持。主要用到的方法列match 是從頭開始匹配\w 匹配字符(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)4個斜杠 代表批評一個斜杠匹配多行1、匹配ip地址,\d{1,3}表示匹配一個數字,1到3位數字。 如果把192 改成1932,則匹配的位數必須含4,否則匹配不到,如果還是\d{1,3},則匹配不到1932;下標點必須用轉譯符\ip_addr = "inet 192.168.60.223 netmask 0xffffff00 broadcast 192.168.60.255"m = re.search("\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}", ip_addr)print(m.group())2、匹配手機號phone_str?=?"hey my name is alex, and my phone number is 13651054607, please call me if you are pretty!"phone_str2?=?"hey my name is alex, and my phone number is 18651054604, please call me if you are pretty!"m?=?re.search("(1)([358]\d{9})",phone_str2)if?m:????print(m.group())匹配方式是"(1)([358]\d{9})",以1開頭,第二位是7358種的一個,后面匹配九個數字,共11位。1[7358]\d{9} 這是單個號碼的 1開頭,第二位是7358中的一個,后面還有9個數字,共11位 。/(1[7358]\d{9}\s*,\s*)*(1[7358]\d{9})/ 這是多個號碼的 解釋: 1[7358]\d{9} #匹配一個號碼 \s*,\s* #匹配號碼之間的逗號,號碼和逗號之間允許有空格也就是\s* (1[7358]\d{9}\s*,\s*)* #整體合起來,*星號表示可以重復任意次,也就是可以有多個號碼 (1[7358]\d{9}) #最后一個用來匹配沒有逗號的號碼3、re.split # 將匹配到的格式當做分割點對字符串分割成列表>>>m?=?re.split("[0-9]",?"alex1rain2jack3helen rachel8")>>>print(m)***********************************正則表達式中(...)的意思是 匹配封閉括號中的正則表達式(RE),并保存為子組***********************************有三層花括號,怎么用正則表達式匹配到最里層的花括話??比如{1 2 3 { 4 5 { 6 7 } } }?要輸出 6 7>>> import re
>>> s="{1 2 3 { 4 5 { 6 7 } } } ">>> reg=re.compile(r"\{[^{}]*\}")>>> reg.search(s).group(0)'{ 6 7 }'>>>**********************************文本應該是這樣的:<SPAN><P>eng li aas<SS>ddde<AP>iiiiideeeeef<P>怎樣在Python中用正則表達式提取出尖括號之外的內容?即最后的輸出結果為eng li aas d dde iiiii deeeeef最佳答案**************************rule1 = '\([^\(\)]+\)'#取出內層括號內容 []內表示一對括號內 不包含 左括號或者右括號 ,整個表達式 是取在()內不包含左右括號的表達式。^ 表示非的意思,如果在[]外,表示以后邊的字符開頭,如果在[]內,表示非后邊的字符。rule2 = '[\-]{0,1}\d+[\.]{0,1}\d*[\*\/]{1}[\-]{0,1}\d+[\.]{0,1}\d*'#計算乘除 、#rule2?=?'[\-]{0,1}\d+[\.]{0,1}\d*[\*\/]{1}[\-]{0,1}\d+[\.]{0,1}\d*'?分三部分#num1?=?[\-]{0,1}\d+[\.]{0,1}\d*?比如?-1.2?或者2?#運算符號?=?[\*\/]{1}?必須有一個乘號或除號#num2?=?[\-]{0,1}\d+[\.]{0,1}\d*??也是?-1.x或者?#是把乘號除號前后兩個數字取出來,這兩個數字可能為負的也可能帶小數點rule3 = '[\-]{0,1}\d+[\.]{0,1}\d*[\+\-]+\d+[\.]{0,1}\d*'#計算加減***********正則表達式 參考鏈接http://www.jb51.net/tools/zhengze.html***********
http://www.jb51.net/article/65286.htm
import rerule1 = 'abc'
pattern = re.compile(r'hello')
args = 'hello world! where is abcd'
res = re.search(pattern, args)
if res:
res = res.group()
print('result:%s'%res)#
?
?
轉載于:https://www.cnblogs.com/20160925oldboy/p/6079586.html
總結
以上是生活随笔為你收集整理的一鼓作气 博客--第六篇 note6的全部內容,希望文章能夠幫你解決所遇到的問題。