描述
dict2json_file() 將字典存儲為json文件。
dict2json_file() 接收兩個(gè)參數,第一個(gè)參數為要存儲的數據,第二個(gè)參數為存放的路徑+文件名。
語(yǔ)法
以下是 dict2json_file() 的語(yǔ)法:
dict2json_file(dict, file='temp/temp.json')
參數
● dict [dict]:要存儲的字典數據。
● file [str]:要儲存的路徑+文件名。
返回值
無(wú)返回值。
實(shí)例
以下展示了使用 dict2json_file() 的實(shí)例:
from kyger.utility import dict2json_file print(dict2json_file({"name": "kgcms", "www": "http://www.kgcms.com"}, file='static/kgcms.json')) # 將字典轉成json寫(xiě)入到文件
結果
以上實(shí)例運行后輸出的結果為:
'# static/kgcms.json文件內容:{"name": "kgcms", "www": "http://www.kgcms.com"}
適應版本
v1.0.1