Warning: This is a hack
There's probably a better way to do this, but I've used it for years and it suits my purposes:
Also, probably won't work on MS Windows since I use symbolic links. Not sure, I'm pretty much
A Linux only person.
├── data
│ ├── csv
│ ├── PDF
│ └── tmp
├── docs
├── src
│ ├── ProvingGround
│ └──
│ ├─ MyProg.py
│ └── Create symbolic link to MyPaths.py here
└── venv
└── ...
then to use MyPaths in MyProg.py, instanceiate like
if you have more directories below Proving Ground, increase size of depth accordingly
EDIT:
Note You most likely figured this out, depth is optional, 0 is assumed if not supplied.
There's probably a better way to do this, but I've used it for years and it suits my purposes:
Also, probably won't work on MS Windows since I use symbolic links. Not sure, I'm pretty much
A Linux only person.
import os from pathlib import Path class MyPaths: def __init__(self, depth=0): os.chdir(os.path.abspath(os.path.dirname(__file__))) dir_depth = abs(depth) HomePath = Path(".") while dir_depth: HomePath = HomePath / ".." dir_depth -= 1 rootpath = HomePath / ".." self.datapath = rootpath / "data" self.datapath.mkdir(exist_ok=True) self.csvpath = self.datapath / "csv" self.csvpath.mkdir(exist_ok=True) self.docpath = rootpath / "docs" self.docpath.mkdir(exist_ok=True) self.jsonpath = self.datapath / "json" self.jsonpath.mkdir(exist_ok=True) self.htmlpath = self.datapath / "html" self.htmlpath.mkdir(exist_ok=True) self.pdfpath = self.datapath / 'PDF' self.pdfpath.mkdir(exist_ok=True) self.tmppath = self.datapath / "tmp" self.tmppath.mkdir(exist_ok=True) if __name__ == "__main__": MyPaths(depth=0)now if you have a source directory like:
├── data
│ ├── csv
│ └── tmp
├── docs
├── src
│ ├── ProvingGround
│ └──
│ ├─ MyProg.py
│ └── Create symbolic link to MyPaths.py here
└── venv
└── ...
then to use MyPaths in MyProg.py, instanceiate like
mpath = MyPaths(depth=1)
if you have more directories below Proving Ground, increase size of depth accordingly
EDIT:
Note You most likely figured this out, depth is optional, 0 is assumed if not supplied.