Behaviour of os.path.join

Ben Bacarisse ben.usenet at bsb.me.uk
Tue May 26 11:22:27 EDT 2020


BlindAnagram <blindanagram at nowhere.com> writes:

> I came across an issue that I am wondering whether I should report as an
> issue.  If I have a directory, say:
>
>   base='C:\\Documents'
>
> and I use os.path.join() as follows:
>
>   join(base, '..\\..\\', 'build', '')

It rather defeats the purpose of os.sep if you include it in a part of
the path.  What you mean is better expressed as

  join(base, '..', '..', 'build', '')

(and base includes it too, but I can't suggest an alternative because I
don't know your intent is far as defaults go.)

<cut>
> The documentation says that an absolute path in the parameter list for
> join will discard all previous parameters but '\\' is not an absoute
> path!

I think it is.  The picture is messy on Windows (because of the drive
letter) but absolute paths are usually taken to be those that start with
a path separator.

-- 
Ben.


More information about the Python-list mailing list