Suppose there are 20 JSON files in a folder and I want to read & store them into 20 different dictionaries in a python program.
You may use a list
to hold the filenames, then apply the dict reading for each
import json
from pathlib import Path
files = ['a.txt', 'b.txt', 'c.txt'] # ...
dicts = [json.loads(Path(file).read_text()) for file in files]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.