Skip to content

Commit 2186989

Browse files
author
mark.liu
committed
新增 Python dict to json 如何轉換?提供範例給你參考 程式碼
1 parent 1332b4b commit 2186989

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

Python/DictToJson/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
文章名稱:Python dict to json 如何轉換?提供範例給你參考
2+
3+
文章連結:https://shareboxnow.com/python-dict-to-json/
4+
5+
程式碼位置:https://github.com/MarkwwLiu/PythonBasicTeaching/tree/master/Python/DictToJson
6+
7+
執行方式: `python3 dict_to_json.py `
8+

Python/DictToJson/__init__.py

Whitespace-only changes.

Python/DictToJson/dict_to_json.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import json
2+
import os
3+
from datetime import datetime
4+
# 範例的字典檔案
5+
example_dict = {
6+
"123": "tttt",
7+
"1123": ["123", "fffff"],
8+
"fffff": "awinni12344%%^^",
9+
"kkkkffff": "你好啊!!"
10+
}
11+
12+
13+
def main(save_json_path, save_json_name, dataDict):
14+
"""
15+
:param save_json_path: 你要儲存json的位置
16+
:param save_json_name: 你要將字典存入到json的檔案名稱叫做什麼
17+
:param dataDict: dict資料
18+
"""
19+
now_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
20+
21+
with open(save_json_path + save_json_name + ".json", 'w') as json_file:
22+
json.dump(dataDict, json_file)
23+
print("[%s] Json 檔案儲存至: %s" % (now_time, save_json_path + save_json_name + ".json"))
24+
25+
26+
if __name__ == '__main__':
27+
main(save_json_path=os.getcwd() + '/', save_json_name="test", dataDict=example_dict)

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ Python基本教學,詳細資訊請查看我的部落格:https://shareboxnow.
3939

4040
程式碼位置:https://github.com/MarkwwLiu/PythonBasicTeaching/tree/master/GoogleDrive/UploadFile
4141

42+
#
43+
文章名稱:python上傳檔案到Google Drive 指定的資料夾,程式碼大公開,詳細解說
44+
45+
文章連結:https://shareboxnow.com/python-google-drive-2/
46+
47+
程式碼位置:https://github.com/MarkwwLiu/PythonBasicTeaching/tree/master/GoogleDrive/UploadFileSpecifiedFolder
48+
4249
---
4350
# Python
4451

0 commit comments

Comments
 (0)