'How can I return data from a .json file with Discord.py
I want to store data in a .json file, and I want to also be able to fetch this data by using a discord bot using discord.py
Solution 1:[1]
I wouldn't use json, but instead use a database like MongoDB
Still want to use json? Use the json module that is built in to python.
Solution 2:[2]
import json
data = {
"foo": "bar"
}
#write json to file
file = open('json.json', "w")
json.dump(data, file);
#read json from file
file = open('json.json', 'r')
jstring = json.load(file)
#output: bar
print(jstring['foo'])
A simple google trick would of done it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | kidney bean |
| Solution 2 | Octo |
