Python連載47-json文件、正則表達式初步

1、在線工具html

1.https://www.sojson.com/python

2.http://www.w3cshool.com.cn/json/git

3.http://www.runoob.com/json/json-tutorial.htmlgithub

2、JSON(JavaScriptObjectNotation)正則表達式

1.json格式是一個鍵值對形式的數據集json

(1)key:字符串(2)value:字符串,數字,列表,json微信

(3)json使用大括號包裹(4)鍵值對直接用逗號隔開工具

2.json和python格式的對應學習

(1)字符串-字符串(2)數字-數字(3)隊列-list(4)對象-dict(5)布爾值-布爾值,不過python中的布爾值首字母是大寫的大數據

3.python for json

(1)json包

(2)json和python對象的裝換

json.dumps():對數據編碼,把python格式轉換爲json格式

json.loads():對數據進行解碼,把json格式轉換爲python格式

import json student={ "name":"liuming", "age":18, "mobile":"15847562589" } print(type(student)) stu_json = json.dumps(student) # print(stu_json)

print("JSON對象:{0}".format(stu_json)) stu_dict = json.loads(stu_json) print(stu_dict) print(type(stu_dict)) 

(3)python讀取json文件

json.dump():把內容寫入文件

json.loads():把json文件內容讀入python

 

 

data = {"name":"hahah", "age":15 } with open("t.json","w") as f: json.dump(data,f)#將python數據轉換成json格式寫到文件f中去
 ​ with open("t.json","r") as f: d = json.load(f) print(d) 

3、正則表達式

1.用於使用單個字符串來描述,匹配符合某個規則的字符串,經常用來檢索,替換某些模式的文本

2.正則的寫法

.(點號)​:表示任意字符,除了\n​,​好比:查找全部的一個字符\.

[]:匹配中括號中列舉的任意字符,​好比:[L,Y,0],

\d:任意一個數字

\D:除了數字均可以

\s:表示空格,tab鍵

\S:表示空白符號

\w:單詞字符,就是a-z.A-Z,0-9,_

\W:除了單詞字符

*​:表示前面的內容重複零次或者屢次​

4、源碼

D30_5_JsonAnalysis.py

D30_6_RegularExpression.py

https://github.com/ruigege66/Python_learning/blob/master/D30_5_JsonAnalysis.py

https://github.com/ruigege66/Python_learning/blob/master/D30_6_RegularExpression.py

2.CSDN:https://blog.csdn.net/weixin_44630050(心悅君兮君不知-睿)

3.博客園:https://www.cnblogs.com/ruigege0000/

4.歡迎關注微信公衆號:傅里葉變換,我的公衆號,僅用於學習交流,後臺回覆」禮包「,獲取大數據學習資料

 

相關文章
相關標籤/搜索