Add readlines_generator.
This commit is contained in:
parent
5a76734072
commit
acaabb7d61
1 changed files with 9 additions and 0 deletions
|
@ -2,6 +2,7 @@ import glob
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
|
import typing
|
||||||
|
|
||||||
_glob = glob
|
_glob = glob
|
||||||
|
|
||||||
|
@ -440,6 +441,14 @@ class Path:
|
||||||
with self.open(mode, **kwargs) as handle:
|
with self.open(mode, **kwargs) as handle:
|
||||||
return handle.readlines()
|
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
|
@property
|
||||||
def relative_path(self):
|
def relative_path(self):
|
||||||
return self.relative_to(cwd())
|
return self.relative_to(cwd())
|
||||||
|
|
Loading…
Reference in a new issue