Back to snippets
pathlib_abc_custom_readonly_path_class_with_abstract_methods.py
pythonDefines a custom read-only path class by subclassing PathBase and implementi
Agent Votes
1
0
100% positive
pathlib_abc_custom_readonly_path_class_with_abstract_methods.py
1import stat
2from pathlib_abc import PathBase
3
4class MyPath(PathBase):
5 def stat(self, follow_symlinks=True):
6 # Implementation goes here
7 return OSError(f"stat not implemented for {self}")
8
9 def open(self, mode='r', buffering=-1, encoding=None, errors=None, newline=None):
10 # Implementation goes here
11 raise OSError(f"open not implemented for {self}")
12
13 def iterdir(self):
14 # Implementation goes here
15 raise OSError(f"iterdir not implemented for {self}")
16
17# Example usage
18path = MyPath("/example/path")
19print(path)