[Python-ideas] os.path.join

random832 at fastmail.us random832 at fastmail.us
Mon Nov 4 18:29:57 CET 2013


On Mon, Nov 4, 2013, at 11:07, Chris Angelico wrote:
> Then os.path.join is probably the wrong tool for the job. Do you want
> to collapse "/foo/bar" + "../quux" into "/foo/quux"? That rewrites the
> first. If not, don't use a function that does that. Try simple string
> concatenation instead.

>>> posixpath.join('/foo/bar','../quux')
'/foo/bar/../quux'
>>> macpath.join('foo:bar','::quux')
'foo:bar::quux'

The old mac module (and VMS if it existed) demonstrates join does more
than simply put two things together with sep between (also neatly
demonstrating why "simple string concatenation" is not a viable
solution), so this is clearly deliberate behavior rather than something
that merely "falls out of" a naive implementation as one could assume
the posix one to be.

I did, incidentally, notice a bug in macpath's *split* function;
macpath.split(':foo::bar') should return (':foo::','bar') rather than
(':foo:','bar').



More information about the Python-list mailing list