Behaviour of os.path.join

BlindAnagram blindanagram at nowhere.com
Wed May 27 12:39:32 EDT 2020


On 27/05/2020 16:49, Rhodri James wrote:
> On 27/05/2020 16:12, BlindAnagram wrote:
>> I'm sorry that you don't believe me but all I know is how I intend the
>> path to be used.  And the os.path functions aren't helpful here when
>> they actually_change_  the meanings of paths on Windows:
>>
>>>> fp= "C:\\Documents\finance\\"
>>>> abspath(fp)
>> 'C:\\Documents\\finance'
>>
>> If you believe these 'before' and 'after' paths are the same I can only
>> assume that you don't work on Windows (where one refers to a directory
>> and the other a file without an extension).
> 
> More accurately, one is not a legal filename but both are legal
> directory names.

If they are to be created, which is my situation, the result will be a
diretory and a file.

> I entirely believe that you have a problem, but I'm inclined to think
> it's of your own making.  You seem to have decided how paths work
> without checking whether the language agrees with you.  It doesn't, and
> hasn't for over a decade without a significant number of complaints (as
> in I can't remember the last one, and I've been around here for a while
> -- it's too hot for me to want to go hunt in the archives :-).

Why do you believe my understanding of Python is lacking?  It seems to
me that I have tried to avoid this very issue by explicitly sending a
directory and I have been thwarted by a combination of poor knowledge
elsewhere and a poorly designed function that changes the semantics of
what it is offered.

I would be surprised if issues such as these were not, at least in
significant part, the reason why we now have pathlib.

> How are these unexpected extensionless files getting created?

I believe by attempting to make the directory I send absolute with
abspath() and then copying a file to this path.  They expected this to
copy the file into the directory with its original name but instead it
copies it to the file that abspath 'kindly' converts my directory into.

I did complain about their lack of knowledge but I also have a right to
complain about a function that converts an explicitly specified
directory into a file :-)


More information about the Python-list mailing list