-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Feature proposal: Pathlib-like path objects #38415
Comments
Also, a couple things to note on your proposal
|
@rofinn sure, as said, this is a minimalistic proof-of-concept with very limited functionality. Pros of this approach is that it minimizes the risk of any conflicts and problems with backward compatibility, since currently paths are just strings. The cons are the ones mentioned by you. |
Fair enough, seems like the practicality vs purity discussion. Might be worth reviewing the design choices for pathlib, since that's what you're trying to model the behaviour after? https://snarky.ca/why-pathlib-path-doesn-t-inherit-from-str/ |
Implemented in https://github.com/rofinn/FilePathsBase.jl. However, we are not going to suddenly deprecate using Strings as Paths in Base. |
Python has great, build-in, pathlib module, that enables users to dynamically manipulate system paths. Much of its functionality is already covered by Julia's base module utilities (
relpath
,abspath
, etc.), but one of the most handy, while trivial, functionalities is not covered. Pathlib enables users to create paths dynamically, e.g.Path("foo") / "bar"
createsPath("foo/bar")
etc, while sticking to system convention forjoinpath
-like path creation.Example
Say that you are dealing with data in nested directories, you need to loop over the directories. With the proposed functionality, you could do this with simple and readable code:
POC implementation
This is trivial to implement in Julia:
and here some examples of usage:
Since it'd inherit from
AbstractString
, it is compatible with other string-based methods. If this would get accepted, methods likepwd
,joinpath
,relpath
, etc. could returnPath
objects instead of regular strings, so we could use them likepwd() / "foo" / "bar"
to create the./foo/bar
path dynamically.The text was updated successfully, but these errors were encountered: