Add convenient pathclass.read, write.
This commit is contained in:
parent
39d6140138
commit
0a1ab15637
1 changed files with 21 additions and 0 deletions
|
@ -275,6 +275,20 @@ class Path:
|
|||
parent = os.path.dirname(self.absolute_path)
|
||||
return self.spawn(parent)
|
||||
|
||||
def read(self, mode, **kwargs):
|
||||
'''
|
||||
Shortcut function for opening the file handle and reading data from it.
|
||||
'''
|
||||
with self.open(mode, **kwargs) as handle:
|
||||
return handle.read()
|
||||
|
||||
def readlines(self, mode, **kwargs):
|
||||
'''
|
||||
Shortcut function for opening the file handle and reading lines from it.
|
||||
'''
|
||||
with self.open(mode, **kwargs) as handle:
|
||||
return handle.readlines()
|
||||
|
||||
@property
|
||||
def relative_path(self):
|
||||
return self.relative_to(os.getcwd())
|
||||
|
@ -358,6 +372,13 @@ class Path:
|
|||
def with_child(self, basename):
|
||||
return self.join(os.path.basename(basename))
|
||||
|
||||
def write(self, mode, data, **kwargs):
|
||||
'''
|
||||
Shortcut function for opening the file handle and writing data into it.
|
||||
'''
|
||||
with self.open(mode, **kwargs) as handle:
|
||||
return handle.write(data)
|
||||
|
||||
def common_path(paths, fallback):
|
||||
'''
|
||||
Given a list of file paths, determine the deepest path which all
|
||||
|
|
Loading…
Reference in a new issue