Skip to content

path_elements up to project root bot to fs root #4628

Answered by mwichmann
dustdfg asked this question in Q&A
Discussion options

You must be logged in to vote

path_elements (note the more official way is to use the get_path_elements() method, though neither are considered "published API") works additively - each node created adds itself to the list it got from its parent directory, which it got after amending its parent's, so on all the way up to the root; there's no filtering capability or argument to return a subset of that.

If you just want the strings, you can use a relative path, make a pathlib path out of it, and use its parts attribute - but you'll still have to add the pieces together - that is,

pathlib.PurePath('src/dir/file.c')  --> ('src', 'dir', 'file.c')  # and not ("src", "src/dir", etc.

which is probably no simpler than just doi…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@dustdfg
Comment options

@mwichmann
Comment options

Answer selected by dustdfg
@dustdfg
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants