Behaviour of os.path.join

BlindAnagram blindanagram at nowhere.com
Wed May 27 11:12:02 EDT 2020


On 27/05/2020 14:53, Rhodri James wrote:
> On 27/05/2020 14:41, BlindAnagram wrote:
>> That is true if you know for sure how your path will be used.
>>
>> But if you don't, there is a world of difference between passing the
>> paths 'name' and 'name\\' on for others to use. And in this situation it
>> doesn't help when os.path functions strip the directory separator off.
> 
> Only if you impose meaning externally, which implies you do know how
> your path will be used after all.  If you want to know whether a given
> path corresponds to a file or a directory on a filing system, there's no
> real substitute for looking on the filing system.  Anything else is, as
> you have discovered, error-prone.

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 information about the Python-list mailing list