On Wed, Jan 06, 2021 at 07:07:30AM +0300, Mikhail V wrote: > I'd like to have an option to force the path separator for the > "os.path.join()" method. > E.g. if I run the script on Windows, but I generate, say, an URL, I'd > find it convenient > to use the same method, but with an explicit flag to "join" with the > forward slash (because URLs use it).
"I don't care about correctness, I want to add arbitrary functionality to unrelated functions because it's convenient." *wink* The whole point of using os.path.join is that you don't care what the separator is, so long as it is correct *for the OS at runtime*. But for URLs, the separator never depends on the runtime OS. It is either fixed, or at worst will depend on the protocol. URLs are also a lot more complicated than file paths, so you should be using urllib to assemble the parts: https://docs.python.org/3/library/urllib.parse.html If you can't be bothered (and let's be honest, we've all been there) there's nothing wrong with assembling URL path components with pure string operations. All you need is a one-liner: def join(*parts, sep='/'): return sep.join([part.strip(sep) for part in parts]) -- Steve _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/5LHVWVNAXJWCLKPYHUHA25TMXWB6L2XG/ Code of Conduct: http://python.org/psf/codeofconduct/