My json file is a list of dictionaries
I am able to successfully open it but I am not sure how to access the "the_dict" dictionary so I can retrieve and print just "test" and "pie" in my python program.
with open('my_settings.json') as json_data:
config = json.load(json_data)
# my_words = config["the_dict"] is what I tried but this does not work
config_file
is a list, not a dictionary, as you have observed. You will need to access the first dictionary in the list, and then call the key "the_dict"
then "words"
to get the list of words:
my_words = config_file[0]["the_dict"]["words"]
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.