Charles Stanhope

Charles Stanhope at

@Clacke moved to quitter.se and microca.st I understand the behavior. I just think the function is misnamed. You just described it's operation as a series of 'cd' invocations. That's not a join operation. That's a 'virtual_cd_chain' or something. :)

But on top of that:

>>> os.path.join("path", ".",".",".")
'path/././.'

Which is not what you would get with a series of 'cd' commands. So the function sort of works like you said, except when it doesn't. ;)

Anyway, all languages have their quirks, and it turns out that for most of my use cases, os.path.join() does not have desirable behavior. But that's okay because I was able to create a one line replacement that did what I needed it to do. I just have to remember to use it. :)

By the way, my use case is creating directories that hold the rootfs of a container or disk image. It's very natural to refer to "/etc" or the "/bin" of the destination rootfs and have the tool place things in their correct place relative to some starting directory in the host. In this situation, I wanted to "join" two paths to each other, so I reached for the os.path.join() function and learned a very valuable lesson. :)