On 2021-01-06 at 07:07:30 +0300,
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.
> 
> I know there is the "pathlib" module with all conversion methods, but
> it's overkill for many
> tasks. So I'd rather like to have an option to write for example:
> 
>     path = os.path.join (root, dir, sep = "posix")
> 
> So that it joins with the forward slash even if run on Windows.
> Also it seems that e.g. "os.path.split()" already supports both
> separators, so I think this addition won't bring inconsistency into
> the module and its usage.

I'm not sure whether a method in the os module should understand URLs
(are URLs part of the OS, or part of something else?), but in any case,
in your example, it would make more sense to have a "URL" separator and
not use "posix" as a simple synonym for forward slash.  IMO, using "/"
itself is clearer.

That said, AIUI, there's nothing stopping a web server from using
whatever separators it wants.  Everything after the domain name is up to
the web server to interpret; it just happens that most early web servers
ran on Unix/Posix/Linux boxes and mapped URLs fairly directly to parts
of the file system, and "/" was more natural than anything else.
_______________________________________________
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/5KGGSYF4NLE5MCZXS7D5F2PR6E6RLSNY/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to