[英]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.