[Python-Dev] Re: os.path.commonprefix breakage (original) (raw)

Fred L. Drake, Jr. fdrake@beopen.com
Thu, 17 Aug 2000 00:11:44 -0400 (EDT)


Skip Montanaro writes:

I'm sure it can be argued that the slash should be there. The previous behavior was clearly broken, however, because it was advancing character-by-character instead of directory-by-directory. Consequently, calling

os.path.commonprefix(["/home/swen", "/home/swenson"])

would yield the most likely invalid path "/home/sw" as the common prefix.

You have a typo in there... ;)

It would be easy enough to append the appropriate path separator to the the result before returning. I have no problem with that. Others with more knowledge of path semantics should chime in. Also, should the behavior be

I'd guess that the path separator should only be appended if it's part of the passed-in strings; that would make it a legitimate part of the prefix. If it isn't present for all of them, it shouldn't be part of the result:

os.path.commonprefix(["foo", "foo/bar"]) 'foo'

-Fred

-- Fred L. Drake, Jr. BeOpen PythonLabs Team Member