Subclassing of pathlib.Path
In my case, I wanted to enhance the functionality of pathlib.Path
to include additional methods for file or directory operations specific to my project.
For example, I wanted to add a method that would allow me to easily zip a directory or a file directly from the Path
object:
from pathlib import Path
class EnhancePath(Path):
def zip(self):
print('zip file')
EnhancePath.cwd()
This code works normally on python 3.13
, but it raises an error on python 3.11
and below (I don't test on 3.12
):
AttributeError: type object 'EnhancePath' has no attribute '_flavour'