What is the best way to find string in txt file by using python?
问题 there must be various ways to find string in txt file by using python, but what is the best way? ( for speed, for resources .. ) My first idea was as below. file = open('/home/socfw/src/edl/outbound_monthly.txt') inputIP = '127.0.0.1' while (1): line = file.readline() if inputIP in line: print("ok") break But, it's too slow to use web service properly (it is actually backend logic of my web service) txt file looks like as below test.txt ( IPV4 addresses are in here, and they counts almost 60k