你好,我在我的基于python的迷你聊天机器人中出错了。 在我运行CommandPrompt时,会出现如下错误消息: TypeError:“list”对象不可用
这是我的密码:
import re
import random
response = (
("hello", ("Hi!", "Hello!", "Greetings!", "Howdy!")),
("hi", ("Hi!", "Hello!", "Greetings!", "Howdy!")),
)
pronouns = {
"i'm": "you're",
"i": "you"
}
random.seed()
print("I am psychiatrist bot. I can make you feel better. Tell me how you're feeling!")
while True:
input = re.split("[\.!?]",input("> ").lower().rstrip(".!?")) # <-- Error
full_reply=' '
for sentence in input:
sentence=sentence.lstrip()
for pattern in responses:
wildcards = []
if re.match(pattern[0], sentence):
wildcards = filter(bool, re.split(pattern[0], sentence))
# replace pronouns
wildcards = [' '.join(pronouns.get(word, word) for word in wildcard.split()) for wildcard in wildcards]
response = random.choice(pattern[1])
response = response.format(*wildcards)
full_reply+=response+' '
break
print(full_reply)
您正在覆盖(然后尝试使用)内置函数
input
;在循环的第二次运行中input
将是list
。你知道吗错误消息可能是
list
不可调用。你知道吗相关问题 更多 >
编程相关推荐