Answer the question
In order to leave comments, you need to log in
Error while writing json to file?
read about json , from there I realized that they use
with open("file.json", 'w+') as f :
cl = {}
json.dump(cl, f)
here is my case:if not str(message.chat.id) in os.listdir('mat/'):
os.mkdir('mat/'+str(message.chat.id))
with open("mat/" + str(message.chat.id) + "/users_mat.json", 'w+') as f :
cl = {}
json.dump(cl, f)
print('111111111111')
f = open("mat/" + str(message.chat.id) + "/users_mat.json", 'w+')
users_mat =json.load(f)
if not str(message.from_user.id) in users_mat.keys():
users_mat[str(message.from_user.id)]: 0
json.dump(users_mat , f)
users_mat[str(message.from_user.id)]: users_mat [str(message.from_user.id)]+1
json.dump(users_mat ,f)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question