Answer the question
In order to leave comments, you need to log in
Why is the data from the database displayed with extra characters?
Good evening. I am writing a bot. The essence is simple, the user clicks on the desired button, and then the bot edits the message to the text that the code forms by pulling the text from several SQLite database cells. I am using the PyTelegramBotApi library. But the data is displayed in brackets, quotes and a comma at the end. How to fix it? Thanks in advance to everyone for your help.
Output:
('Пример названия',)
----------------------------------
('Тут много текста ...',)
Цена: ('2500000',)
def product_name(id ):
with sqlite3.connect('database.db') as connection:
cursor = connection.cursor()
cursor.execute("SELECT `name` FROM `catalog` WHERE `id` = ? ", (id,))
result = cursor.fetchone()
return result
def product_about(id ):
with sqlite3.connect('database.db') as connection:
cursor = connection.cursor()
cursor.execute("SELECT `about` FROM `catalog` WHERE `id` = ? ", (id,))
result = cursor.fetchone()
return result
def product_price(id ):
with sqlite3.connect('database.db') as connection:
cursor = connection.cursor()
cursor.execute("SELECT `price` FROM `catalog` WHERE `id` = ? ", (id,))
result = cursor.fetchone()
return result
if call.data == 'bud-1':
markup = types.InlineKeyboardMarkup(row_width=1)
item1 = types.InlineKeyboardButton("Назад", callback_data='bud')
markup.add(item1)
bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=str(product_name('bud1')) + "\n" + "----------------------------------\n" + str(product_about('bud1')) + "\n" + "\n"+"Цена: " + str(product_price('bud1')), parse_mode='html', reply_markup=markup)
Answer the question
In order to leave comments, you need to log in
You will convert the tuple to a string:
>>> a = ("foo",) # кортеж из одного значения
>>> str(a) # преобразовать в строку
"('foo',)"
>>> a[0] # получить значение
'foo'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question