hscommon.path¶
-
class
hscommon.path.Path¶ A handy class to work with paths.
We subclass
tuple, each element of the tuple represents an element of the path.Path('/foo/bar/baz')[1]–>'bar'Path('/foo/bar/baz')[1:2]–>Path('bar/baz')Path('/foo/bar')['baz']–>Path('/foo/bar/baz')str(Path('/foo/bar/baz'))–>'/foo/bar/baz'
-
is_parent_of(other)¶ Whether
otheris a subpath ofself.Almost the same as
other in self, but it’s a bit more self-explicative and whenother == self, returns False.
-
parent()¶ Returns the parent path.
Path('/foo/bar/baz').parent()–>Path('/foo/bar')
-
property
name¶ Last element of the path (filename), with extension.
Path('/foo/bar/baz').name–>'baz'
-
hscommon.path.log_io_error(func)¶ Catches OSError, IOError and WindowsError and log them
-
hscommon.path.pathify(f)¶ Ensure that every annotated
Patharguments are actually paths.When a function is decorated with
@pathify, every argument with annotated as Path will be converted to a Path if it wasn’t already. Example:@pathify def foo(path: Path, otherarg): return path.listdir()
Calling
foo('/bar', 0)will convert'/bar'toPath('/bar').