Skip to content

Instantly share code, notes, and snippets.

@AFutureD
Created April 28, 2020 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AFutureD/2a00d9118639152a1e00b8f1fdf7a310 to your computer and use it in GitHub Desktop.
Save AFutureD/2a00d9118639152a1e00b8f1fdf7a310 to your computer and use it in GitHub Desktop.
#Python #Inherit pathlib.Path
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