Answer the question
In order to leave comments, you need to log in
How to remove value from Json?
I have an array keys
that holds stuff
I use del mas[i]
but it doesn't work
Here is my code:
with open('keys.json', 'r', encoding='utf-8') as f: #открыли файл с данными
mas = json.load(f) #загнали все, что получило
print(key)
for i in range(len(mas)):
if (mas[i] == key):
print(mas)
await bot.send_message(
chat_id=message.chat.id,
text = "okay"
)
text = 1
sql.execute(f'UPDATE users SET sub = {text} WHERE user_id = {message.from_user.id}')
int(i)
del mas[i]
else:
await bot.send_message(
chat_id=message.chat.id,
text = "не окей" )
Answer the question
In order to leave comments, you need to log in
You should not iterate the list that you change in the same loop. Well, SQL queries would be compiled differently
if key in mas:
await bot.send_message(chat_id=message.chat.id, text = "okay")
sql.execute('UPDATE users SET sub = ? WHERE user_id = ?', (text, message.from_user.id))
mas.remove(key)
else:
await bot.send_message(chat_id=message.chat.id, text = "не окей" )
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question