我想要做的是检查是否在文本文件中找到此字符串.如果是,我希望它打印出该行,否则打印出一条消息.
到目前为止,我已实现此代码:
def check_string(string):
w = raw_input("Input the English word: ")
if w in open('example.txt').read():
for w.readlines():
print line
else:
print('The translation cannot be found!')
Run Code Online (Sandbox Code Playgroud)
我已经尝试过实现,但是我遇到了语法错误.
它说:
该行的语法无效 - 对于w.readlines():
关于如何使用这行代码的任何想法?