Python readlines() usage and efficient practice for reading
问题 I have a problem to parse 1000's of text files(around 3000 lines in each file of ~400KB size ) in a folder. I did read them using readlines, for filename in os.listdir (input_dir) : if filename.endswith(".gz"): f = gzip.open(file, 'rb') else: f = open(file, 'rb') file_content = f.readlines() f.close() len_file = len(file_content) while i < len_file: line = file_content[i].split(delimiter) ... my logic ... i += 1 This works completely fine for sample from my inputs (50,100 files) . When I ran