-
Notifications
You must be signed in to change notification settings - Fork 351
Open
Description
Python pathlib paths are much cleaner and easier to use than strings, and it is the recommended Python approach for manipulating paths since Python 3.6 (introduced in Python 3.4). When using OpenSim in other libraries that work with Path objects, it is a bit of a pain and a source of errors to have to convert the path into a string.
Path does not do anything that os.path cannot do, it just makes it much easier and cleaner. Here are a few examples:
your_path = Path(__file__).parent / 'models' / 'model.osim'vs
your_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'models', 'model.osim')your_path.stemvs
os.path.splitext(os.path.basename(p))[0]your_path.with_suffix('.txt')vs
good luck- It also allows for more precise type hints:
def process(path: Path)instead ofdef process(path: str)
Metadata
Metadata
Assignees
Labels
No labels