Behaviour of os.path.join

BlindAnagram blindanagram at nowhere.com
Wed May 27 07:54:11 EDT 2020


On 27/05/2020 09:13, Barry Scott wrote:
> 
> 
>> On 26 May 2020, at 18:01, BlindAnagram <blindanagram at nowhere.com> wrote:
>>
>> On 26/05/2020 17:09, Stefan Ram wrote:
>>> Mats Wichmann <mats at python.org> writes:
>>>> an absolute path is one that starts with the pathname separator.
>>>
>>>  The Python Library Reference does not use the term
>>>  "pathname separator". It uses "directory separator"
>>>  (os.sep) and "filename separator" ('/' on Unix).
>>>
>>>  On Windows:
>>>
>>> |>>> import pathlib
>>> |>>> import os
>>> |>>> pathlib.PureWindowsPath('\\').is_absolute()
>>> |False
>>> |>>> pathlib.PureWindowsPath(os.sep).is_absolute()
>>> |False
>>> |>>> pathlib.PureWindowsPath('/').is_absolute()
>>> |False
>>
>> Thanks, that seems to suggest that there is an issue and that I should
>> hence submit this as an issue.
> 
> Can you post the a link to the issue please?

The issue that I raised here was whether the behaviour of os.path.join()
in treating the Windows directory separator '\\' as an absolute path
should be considered a bug.

The behaviour of join came up for me when I tried to use the os.path
functions to create a path that could only ever be used as a directory
and never a file.  The only way that I found to designate a path as a
directory path was to add '\\' at the end.  But this doesn't work in
using os.path becaause the other os.path functions just strip it off and
turn the directories back into files.  I had hoped that join's
documented use of an empty final parameter to add '\\' might behave
differently but it gets stripped off as well :-(

I thought that the description of pathlib behaviour above suported the
view that the os.path.joing behaviour is a bug, and in a sense it does,
but more importantly it an indication that pathib, not os.path, should
be the module of choice for anyone who spends a lot of time manipulating
paths on Windows.


More information about the Python-list mailing list