-
Hi, what is the best (i.e. intended) approach to add and drop trailing slashes? I am currently using >>> u = yarl.URL('https://www.example.com/spam/eggs')
>>> u
URL('https://www.example.com/spam/eggs')
>>> u / ''
URL('https://www.example.com/spam/eggs/') for adding and >>> u = yarl.URL('https://www.example.com/spam/eggs/')
>>> u
URL('https://www.example.com/spam/eggs/')
>>> u.with_path(u.path.removesuffix('/'))
URL('https://www.example.com/spam/eggs') for dropping the slashes, but maybe somebody has a more elegant solution, esp. for the dropping part. |
Beta Was this translation helpful? Give feedback.
Answered by
commonism
Sep 26, 2024
Replies: 1 comment 4 replies
-
@commonism might have opinions on this ^ |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for adding I don't think it'll get any better than
which is even safe, as it does not add a / if the path ends with / already
but could be improved to avoid unnecessary construction
removing / - possible via
or - avoiding the cost of construction if not required:
but it takes a certain angle to recognize elegance in this I guess