naren_paste

Generator_file_read

Jul 25th, 2024
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.22 KB | Source Code | 0 0
  1. def read_file_line_by_line(file_path):
  2.     with open(file_path, 'r') as file:
  3.         for line in file:
  4.             yield line.strip()
  5.  
  6. # Example
  7. for line in read_file_line_by_line('large_file.txt'):
  8.     print(line)
Advertisement
Add Comment
Please, Sign In to add comment