def check():
datafile = file('example.txt')
found = False
for line in datafile:
if blabla in line:
found = True
breakcheck()if True:
print "true"else:
print "false"
紫衣仙女
浏览 629回答 3
3回答
四季花海
您没有检查check()..另外,你的check()函数不返回任何内容。注意不同之处:def check():
with open('example.txt') as f:
datafile = f.readlines()
found = False # This isn't really necessary
for line in datafile:
if blabla in line:
# found = True # Not necessary
return True
return False # Because you finished the search without finding然后,您可以测试check():if check():
print('True')else:
print('False')