[Python-Dev] os.path.normcase rationale? (original) (raw)

R. David Murray rdmurray at bitdance.com
Fri Sep 24 14:17:37 CEST 2010


On Fri, 24 Sep 2010 11:13:46 +0100, Chris Withers <chris at simplistix.co.uk> wrote:

On 18/09/2010 23:36, Guido van Rossum wrote: > course, exists() and isdir() etc. do, and so does realpath(), but the > pure parsing functions don't.

Yes, but: H:>echo foo > TeSt.txt ...>>> import os.path >>> os.path.realpath('test.txt') 'H:\test.txt' >>> os.path.normcase('TeSt.txt') 'test.txt' Both feel unsatisfying to me :-S How can I get 'TeSt.txt' from 'test.txt' (which feels like the contract normcase should have...)

You can't, and you shouldn't be able to. "normalization" is something that happens without reference to existing objects, the whole point is to put the thing into "standard form" so that you can compare strings obtained from different sources and know that they will represent the same object on that filesystem.

> They can be used without a working > filesystem even. (E.g. you can import ntpath on a Unix box and happily > parse Windows paths.)

But what value does that add over just doing a .lower() on the path?

It does what is appropriate for that....oh, yeah. For that OS, not "for that filesystem". (e.g. on Unix normcase does nothing since files with different cases but the same letters are different files.)

Being os specific rather than file system type specific is the usability bug. But to fix it we'll need to introduce a 'filesystems' module enumerating the different file systems we support, with tools for figuring out what filesystem your program is talking to. But normacase still, wouldn't (shouldn't) do what you want.

-- R. David Murray www.bitdance.com



More information about the Python-Dev mailing list