I have a small script that reads a file. After reading a line i’m trying to figure out that the particular line have a especific text in it. For so i do like this
for line in file:
line = line.lower()
if line.find('my string'):
print ('found my string in the file')
reading the file that line.find aways evaluate to true. When i do like
for line in file:
line = line.lower()
if 'one big line'.find('my string'):
print ('found my string in the file')
It evaluate to false, as it suppose to do. As i’m realy new to python programming just for what i’ve shown i just cant think of what i might look for…
It’s better idiomatic python to write this as:
rather than using
.find()if you don’t care about the position within the string.