New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add function to get common path prefix #49005
Comments
os.path.commonprefix returns the common prefix of a list of paths taken character-by-character. This can Ideally, os.path.commonprefix would operate component-by-component, but people rely on the existing I personally prefer the first option. Aside from the semantic change though, it presents the problem of |
A new function sounds like a good solution to me. How about just calling I agree having a path component based prefix function in os.path is base_dir = os.path.commonpath(paths)
rel_paths = [os.path.relpath(p, base_dir) for p in paths] |
The documentation should explain what a "common path prefix" is. It |
I think we need to recognize the inherent limitations of what we can expect Also, as long as we are considering case sensitivity, what about HFS on Mac Skip |
For Windows, os.path.splitunc and os.path.splitdrive should also be
|
The regex based approach to the component splitting when os.altsep is |
There is more developed patch in bpo-10395. |
Feel free to close this ticket. I long ago gave up on it. |
bpo-10395 added “os.path.commonpath” in 3.5. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: