[英]How to read multiple json files stored in a folder into different dictionaries in Python?
假設一個文件夾中有 20 個 JSON 文件,我想在 python 程序中將它們讀取並存儲到 20 個不同的字典中。
您可以使用list
來保存文件名,然后為每個應用讀取
import json
from pathlib import Path
files = ['a.txt', 'b.txt', 'c.txt'] # ...
dicts = [json.loads(Path(file).read_text()) for file in files]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.