-
Использование цикла For:
with open('file.txt', 'r') as file: for line in file: # Process each line here -
Использование метода Readlines():
with open('file.txt', 'r') as file: lines = file.readlines() for line in lines: # Process each line here -
Использование итераторов:
with open('file.txt', 'r') as file: lines_iterator = iter(file) for line in lines_iterator: # Process each line here -
Использование библиотеки Numpy:
import numpy as np lines = np.genfromtxt('file.txt', delimiter='\n', dtype=str) for line in lines: # Process each line here -
Использование библиотеки Pandas:
import pandas as pd lines = pd.read_csv('file.txt', sep='\n', header=None) for line in lines[0]: # Process each line here