Не получается передать переменную в другую функцию
Пытаюсь передать переменную sqlid из categories_edit в функцию new_category, но при попытке поместить sqlid[0] в таблицу, вылезает ошибка:
'NoneType' object is not subscriptable'
def categories_edit(message):
global sqlid
sqlid = c.execute("SELECT id FROM categories WHERE name=?", (message.text,)).fetchone()
categories_keyboard = telebot.types.ReplyKeyboardMarkup(True, True)
categories_keyboard.row('Создать категорию')
if message.text == 'Создать категорию':
msg = bot.send_message(message.chat.id, 'Введите имя новой категории')
bot.register_next_step_handler(msg, new_category)
allcnames = c.execute("SELECT name FROM categories").fetchall()
print(allcnames)
for i in allcnames:
cleari = str(i[0])
if message.text == cleari:
print(sqlid)
allroot = c.execute("SELECT name FROM categories WHERE root=?", (sqlid[0],)).fetchall()
print(allroot)
print('this is allroot')
for i in allroot:
categories_keyboard.row(str(i[0]))
msg = bot.send_message(message.chat.id, 'ok', reply_markup=categories_keyboard)
print(message)
del categories_keyboard
bot.register_next_step_handler(msg, categories_edit)
def new_category(message):
global sqlid
with lock:
count = c.execute('SELECT COUNT(*) FROM categories').fetchone()
print(count[0])
print(sqlid)
msg = bot.send_message(message.chat.id, 'wwakwwkawk')
c.execute(f"INSERT INTO payment_balance VALUES(?,?,?)", (message.text, count, sqlid[0]))