Skip to main content

Get relative path.

Project description

relpath - relative path module

Python package GitHub license

This module eliminates a weakness of pathlib.Path. The class Path returns ValueError if the relative-path is not a subdirectory of the base-path.

Installation

pip install rel-path

Example for error:

from pathlib import Path

base="/home"
rel="/"

# Error when using Path
Path(rel).relative_to(base)

Exception has occurred: ValueError
'/' does not start with '/home'

Example using relpath module:

from relpath import relative_path

base="/home"
rel="/"

print(relative_path(base, rel))
../

Support

If you find any problems with relpath module, please report them to GitHub, and I will respond when possible. Code contributions are always welcome, and ideas for new modules, or additions to existing modules, are also appreciated.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rel-path-1.0.1.tar.gz (2.8 kB view hashes)

Uploaded Source

Built Distribution

rel_path-1.0.1-py3-none-any.whl (3.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page