[Python-ideas] Small enhancement to os.path.splitext

Paul Moore p.f.moore at gmail.com
Tue Apr 20 23:42:33 CEST 2010


On 20 April 2010 17:47, Tarek Ziadé <ziade.tarek at gmail.com> wrote:
> I am not sure to follow the issue. Do you mean that in the same filesystem,
> each directory can treat case sensivity differently ? I wasn't aware of that.

Apologies, I was unclear (I was trying to avoid the term "filesystem"
which isn't an obvious concept on Windows). Putting it more simply,
you need to be able to determine the case sensitivity of the
filesystem to determine if a file "has extension .xxx".

> How would this affect the extension btw ?   I can imagine that
> the path+extensions could to be normalized before the matching job, but
> I don't see other issue, do you have an example ?

As Mike Meyer explained, whether file foo.C "has extension .c" depends
(as far as the user is concerned) on whether the filesystem it's on is
case sensitive.

Many unix utility ports on Windows don't consider this, and they are
quite annoying when the problem hits you (which admittedly isn't that
often). Having an os.path.has_extension function in Python which
doesn't consider case sensitivity would be an attractive nuisance,
encouraging people to write subtly broken code like this. I'm -1 on
such a function.

Having said that, if you can write a function which detects filesystem
case sensitivity (and write a "correct" has_extension function based
on it), you'd be my hero (I believe it's a pretty difficult issue, if
not impossible in the general case).

Paul.



More information about the Python-ideas mailing list