Part of a Python script that I'm writing requires me to find a particular string in a large text or log file: if it exists then do something; otherwise, do something else.
The files which are being fed in are extremely large (10GB+). It feels extremely slow and inefficient to use:
with open('file.txt') as f:
for line in f:
if some_string in line:
return True
return False
If the string doesn't exist in the file, then iterating through would take a long time.
Is there a time efficient way to achieve this?