On 06Jan2021 07:07, Mikhail V <mikhail...@gmail.com> 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).
>Currently I simply use an f-string to combine  a path, like e.g.:
>
>    path = f"{root}/{dir}"
>
>but it will insert extra "/" if there if "root" already has "/" on the end.
>But the "join" method will not, which is a pro for the method vs
>"manual" string construct.

There's also:

    '/'.join(url-path-things-here...)

>I know there is the "pathlib" module with all conversion methods, but
>it's overkill for many tasks.

I suspect given pathlib's existence, that raises the bar for wanting to 
extend os.path.join since there are so many other ways to do that.

Also, os.path.join is supposed to be for the local OS, like most other 
os.* things. Making it _not_ act like the local OS feels antithetical to 
me.

I was going to suggest:

    https://docs.python.org/3/library/urllib.parse.html#module-urllib.parse

since your use case is URLs, but it doesn't really parse the "path" 
part.

Cheers,
Cameron Simpson <c...@cskk.id.au>
_______________________________________________
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/KTWRI3RT35XDO2XQ2L5IBSIWWPHCLG4L/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to