Задать вопрос
@mikitos59

Как упростить код на python?

Как упростить данный код ? можно пример, пожалуйста, буду благодарен)

@dp.message_handler(text='ПН')
async def pn(message: types.Message):
    result = connect(message)
    for row in result:
        if row in groups.keys():
            info = pn_n(groups[row])
            await message.answer(info, reply_markup=il_1)


@dp.message_handler(text='ВТ')
async def pn(message: types.Message):
    result = connect(message)
    for row in result:
        if row in groups.keys():
            info = vt_n(groups[row])
            await message.answer(info, reply_markup=il_3)


@dp.message_handler(text='СР')
async def pn(message: types.Message):
    result = connect(message)
    for row in result:
        if row in groups.keys():
            info = sr_n(groups[row])
            await message.answer(info, reply_markup=il_5)


@dp.message_handler(text='ЧТ')
async def pn(message: types.Message):
    result = connect(message)
    for row in result:
        if row in groups.keys():
            info = ct_n(groups[row])
            await message.answer(info, reply_markup=il_7)


@dp.message_handler(text='ПТ')
async def pn(message: types.Message):
    result = connect(message)
    for row in result:
        if row in groups.keys():
            info = pt_n(groups[row])
            await message.answer(info, reply_markup=il_9)


@dp.callback_query_handler(text='PN_p')
async def answer(call: CallbackQuery):
    result = connect(call)
    if result is None:
        print('none')
    for row in result:
        if row in groups.keys():
            info = pn_p(groups[row])
            await call.message.answer(info, reply_markup=il_2)


@dp.callback_query_handler(text='PN_n')
async def answer(call: CallbackQuery):
    result = connect(call)
    if result is None:
        print('none')
    for row in result:
        if row in groups.keys():
            info = pn_n(groups[row])
            await call.message.answer(info, reply_markup=il_1)

@dp.callback_query_handler(text='VT_p')
async def answer(call: CallbackQuery):
    result = connect(call)
    if result is None:
        print('none')
    for row in result:
        if row in groups.keys():
            info = vt_p(groups[row])
            await call.message.answer(info, reply_markup=il_4)


@dp.callback_query_handler(text='VT_n')
async def answer(call: CallbackQuery):
    result = connect(call)
    if result is None:
        print('none')
    for row in result:
        if row in groups.keys():
            info = vt_n(groups[row])
            await call.message.answer(info, reply_markup=il_3)

@dp.callback_query_handler(text='SR_p')
async def answer(call: CallbackQuery):
    result = connect(call)
    if result is None:
        print('none')
    for row in result:
        if row in groups.keys():
            info = sr_p(groups[row])
            await call.message.answer(info, reply_markup=il_6)


@dp.callback_query_handler(text='SR_n')
async def answer(call: CallbackQuery):
    result = connect(call)
    if result is None:
        print('none')
    for row in result:
        if row in groups.keys():
            info = sr_n(groups[row])
            await call.message.answer(info, reply_markup=il_5)
  • Вопрос задан
  • 106 просмотров
Подписаться 1 Простой Комментировать
Пригласить эксперта
Ответы на вопрос 1
@Andrei1penguin1
Проверку условия в теле функции делай
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы