From 5f69db3d8a81d01adba61771afbbb8d69de01d98 Mon Sep 17 00:00:00 2001 From: "pixeebot[bot]" <104101892+pixeebot[bot]@users.noreply.github.com> Date: Tue, 6 May 2025 03:23:08 +0000 Subject: [PATCH] Limit readline() --- .../01_unstructured_file/g_read_multiple_lines.py | 4 ++-- .../01_unstructured_file/i_reading_large_file.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/python3/11_File_Operations/01_unstructured_file/g_read_multiple_lines.py b/python3/11_File_Operations/01_unstructured_file/g_read_multiple_lines.py index 5bde32b2..26e82ff0 100644 --- a/python3/11_File_Operations/01_unstructured_file/g_read_multiple_lines.py +++ b/python3/11_File_Operations/01_unstructured_file/g_read_multiple_lines.py @@ -15,12 +15,12 @@ print("\ncurrent fh.tell()", fh.tell()) # TO read current line, from cursor position, till end of line -current_line = fh.readline() # -> str +current_line = fh.readline(5_000_000) # -> str print(f"\n{type(current_line) =}") # str type print(f"{current_line =}") print("\ncurrent fh.tell()", fh.tell()) -current_line = fh.readline() # -> str +current_line = fh.readline(5_000_000) # -> str print(f"{current_line =}") diff --git a/python3/11_File_Operations/01_unstructured_file/i_reading_large_file.py b/python3/11_File_Operations/01_unstructured_file/i_reading_large_file.py index 66ba8251..2bfc2ce9 100644 --- a/python3/11_File_Operations/01_unstructured_file/i_reading_large_file.py +++ b/python3/11_File_Operations/01_unstructured_file/i_reading_large_file.py @@ -8,7 +8,7 @@ def read_from_file(file_name): """Method 1 - reading one line per iteration""" with open(file_name, "r") as fp: - yield fp.readline() + yield fp.readline(5_000_000) def read_from_file2(file_name, block_size=1024 * 8):