【发布时间】:2021-12-29 17:55:14
【问题描述】:
所以我试图让 python 搜索我的数据库,然后返回 x 所在的句子 这是我目前的代码
word = input("")
x = open("Database.txt")
for line in x:
if (word) in line:
print(line)
else:
print("This start could not be found, maybe a typo, or try a different start!")
当我在 DataBase.txt 中输入一个单词时出现的错误然后它给出了这个
Traceback (most recent call last):
File "DataSearcher_DataBase2.py", line 1, in <module>
word = input("")
File "<string>", line 1, in <module>
NameError: name 'BrokenRunes' is not defined
当我输入一个不在 DataBase.txt 中的单词时,它会给出我告诉它与 else 做的事情:代码,但是对于没有检测到的每一行,我希望这样只发生一次
【问题讨论】:
-
你在使用 Python 2 吗?
-
我使用的是python版本Python 3.8.0
标签: python database search error-handling