这是我的代码,除了最后一个if语句外,它都能正常工作。
我希望列表成员变为0时,机器人发送以下消息:
"No One"
当列表中有两个机器人说:修复时,此代码将完美工作。
但是当它达到0时,它什么也没说!
from telegram.ext import Updater , CommandHandler , Filters ,
CommandHandler , MessageHandler
from telegram import MessageEntity
from telegram import ParseMode , InputTextMessageContent
updater = Updater("989165404:AAF8DEjyunwrb88-1G8w62cGItzXj1J618g")
list = []
wordsm=["m"]
wordsn=["n"]
def msg_filter(bot , update):
if any (i in update.message.text for i in wordsm):
list.append("{}".format(update.message.from_user.first_name))
bot.send_message(chat_id = update.message.chat_id , text =
"\n".join(list))
if len(list)==2:
bot.send_message(chat_id = update.message.chat_id , text = "FiX!")
if any (j in update.message.text for j in wordsn):
list.remove("{}".format(update.message.from_user.first_name))
bot.send_message(chat_id = update.message.chat_id , text =
"\n".join(list))
if len(list)==0:
bot.send_message(chat_id = update.message.chat_id , text = "No
One")
print(list)
print(len(list))
updater.dispatcher.add_handler(MessageHandler(Filters.text
,msg_filter ))
updater.start_polling()
答案 0 :(得分:1)
请检查缩进。我认为您已经将“如果len(list)== 0:”放在“如果len(list)== 2:”
答案 1 :(得分:1)
也许我不是在看这个,但是看起来像你的
select k.key,
dd.month_start_date,
dd.month_end_date,
( SELECT value
FROM chg_table ct2
WHERE ct2.key = k.key
AND ct2.start_date < dd.month_start_date
ORDER BY ct2.start_date DESC
FETCH FIRST 1 ROW ONLY ) first_value,
( SELECT value
FROM chg_table ct2
WHERE ct2.key = k.key
AND ct2.start_date <= dd.month_end_date
ORDER BY ct2.start_date DESC
FETCH FIRST 1 ROW ONLY ) last_value
from dim_date dd
CROSS JOIN dim_person k
GROUP BY k.key, dd.month_start_date, dd.month_end_date;
嵌套在您的
内部if len(list)==0:
两个条件永远不会同时满足,因此永远不会进入该条件。
也许应该改为:
if len(list)==2: