Created
April 28, 2020 08:19
-
-
Save AFutureD/2a00d9118639152a1e00b8f1fdf7a310 to your computer and use it in GitHub Desktop.
#Python #Inherit pathlib.Path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pathlib import Path | |
class DataSetPath(type(Path())): | |
def __new__(cls, *args, **kwargs): | |
path = cls | |
return super().__new__(cls, *args, **kwargs) | |
def __mod__(self, other): | |
return self.parent / (str(self.name) % other) | |
p = DataSetPath("./dataset") | |
p = p / "%s" | |
print(p) | |
p = DataSetPath("./dataset") | |
p = p / "%s" | |
# DataSetPath('dataset/%s') | |
p = p % "test" | |
# DataSetPath('dataset/test') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment