Behaviour of os.path.join

Chris Angelico rosuav at gmail.com
Wed May 27 16:21:15 EDT 2020


On Thu, May 28, 2020 at 6:14 AM Roel Schroeven <roel at roelschroeven.net> wrote:
>
> Ben Bacarisse schreef op 27/05/2020 om 17:53:
> > There is well-known (*nix) software that relies on a/b/c/ meaning
> > something different to a/b/c but I don't know anyone who thinks this is
> > a good idea.  It causes no end of confusion.
>
> rsync? I always have to look up whether or not I need to use a trailing
> / on the source directory. It's confusing indeed.
>

Possibly, but only as a means of forcing the interpretation. Plain
vanilla cp has the same thing with its destination. If you say "cp a b
c d" and d doesn't exist, cp will create it as a single file; but if
you say "cp a b c d/" then cp will error out if d isn't a directory
(including if it doesn't exist). But if d is a directory, then it
makes no difference which way you do it.

Similarly, a .gitignore file can reference a path name and include a
trailing slash; this forces it to be interpreted as a directory, but
otherwise has the same effect.

A path is a path is a path. Whether it refers to a file, a directory,
a symlink, a named pipe, a socket, or whatever, it's still a path.
Windows does some weird things with drive letters, but the rest of it
is still just a path.

ChrisA


More information about the Python-list mailing list