def checkCache(cachedText):
for line in open("cache"):
if cachedText + ":" in line:
print line
open("cache").close()
else:
requestDefinition(cachedText)
This code searches each line of a file (cache) for a specific string (cachedText + ":").
If it does not find the specific string, within the entire file it is meant to call another function (requestNewDefinition(cachedText)).
However my above code executes the function for each non-matching line.
How can one search a file for a string (cachedText + ":"), and if the string is not found anywhere in the file, execute another function?
Example Cache:
hello:world
foo:bar