From acaabb7d617037e3d286e21cabbce200e51122d0 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sun, 31 Dec 2023 14:16:06 -0800 Subject: [PATCH] Add readlines_generator. --- voussoirkit/pathclass.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/voussoirkit/pathclass.py b/voussoirkit/pathclass.py index 61e8922..ad7064d 100644 --- a/voussoirkit/pathclass.py +++ b/voussoirkit/pathclass.py @@ -2,6 +2,7 @@ import glob import os import re import shutil +import typing _glob = glob @@ -440,6 +441,14 @@ class Path: with self.open(mode, **kwargs) as handle: return handle.readlines() + def readlines_generator(self, mode, **kwargs) -> typing.Generator: + ''' + Shortcut function for opening the file handle and reading lines from it + as a generator instead of a list. + ''' + with self.open(mode, **kwargs) as handle: + yield from handle + @property def relative_path(self): return self.relative_to(cwd())