Last active
April 1, 2025 10:40
-
-
Save mrtj/2dc82607678abbe76bdb1e9082d6eda8 to your computer and use it in GitHub Desktop.
Revisions
-
mrtj revised this gist
Apr 1, 2025 . 1 changed file with 10 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,18 @@ from os import PathLike from typing import Iterator def readlines(filename: PathLike) -> Iterator[str]: """Reads a file line by line, yielding the lines as strings. Unlike Python's file object readlines method, this function does not read the entire file into memory, but reads it on demand. Args: filename: Path to the file to be read Returns: Iterator yielding each line of the file as a string with trailing whitespace removed """ with open(filename, "rt") as f: for line in f: yield line.rstrip() -
mrtj revised this gist
Apr 1, 2025 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,8 +4,8 @@ def read_lines(filename: PathLike) -> Iterator[str]: """Reads a file line by line, yielding the lines as strings. Unlike Python's file object readlines method, this function does not read the entire file into memory, but reads it on demand. """ with open(filename, "rt") as f: for line in f: -
mrtj created this gist
Apr 1, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ from os import PathLike from typing import Iterator def read_lines(filename: PathLike) -> Iterator[str]: """Reads a file line by line, yielding the lines as strings. Unlike python file object's readlines method, this method does not read the entire file in the memory, but reads the file on demand. """ with open(filename, "rt") as f: for line in f: yield line.rstrip()