Skip to content

Current approach to work with trailing slashes #1156

Answered by commonism
hoefling asked this question in Q&A
Discussion options

You must be logged in to vote

for adding I don't think it'll get any better than

u / ''

which is even safe, as it does not add a / if the path ends with / already
but could be improved to avoid unnecessary construction

u / '' if u.parts[-1] != "" else u

removing / - possible via

(u / "").parent

or - avoiding the cost of construction if not required:

u.parent if u.parts[-1] == "" else u

but it takes a certain angle to recognize elegance in this I guess

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@commonism
Comment options

Answer selected by hoefling
@hoefling
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants