Answer the question
In order to leave comments, you need to log in
Writes None in the rating?
Hello, forum users, there is a problem with the rating section in the telegram bot, writes None although I'm trying to display user data by his id in the rating, here is the code:
def get_top_surviveds(self, id):
with self.connection:
self.cursor.execute("SELECT survived FROM stats WHERE user_id = ?", (id, )).fetchone()
self.connection.commit()
bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text='Топ выживших\n Андрей - {0}\n Вова - {1}\n Максим - {2}'.format(sql_lighter.get_top_surviveds(754651730), sql_lighter.get_top_surviveds(982543922), sql_lighter.get_top_surviveds(1720547162)), reply_markup=menu)
Answer the question
In order to leave comments, you need to log in
the code is good, but None can really be
done check, change to 0 (zero) if None or re-request if you need a rating
So the function doesn't return anything. If you need top N, then you can simply immediately return N rows with all data using limit
def get_top_surviveds(self, limit=3):
with self.connection:
return self.cursor.execute("SELECT * FROM stats ORDER BY survived desc LIMIT ?", (limit, )).fetchall()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question