[Pythonmac-SIG] os.path.normcase() and normpath()

Martin Miller mmiller@adobe.com
Mon, 18 Feb 2002 16:58:11 -0800


On Windows, besides converting characters to lowercase, both the
os.path.normcase() and os.path.normpath() functions also replace
forward-slashes '/' with back-slashes '\\' in the path strings. By
itself this seems a little odd because Windows allows forward-slashes to
be used as path separators. Regardless, only the conversion to lowercase
occurs on the Mac, which is also a case-insensitive os. (The normpath()
function also performs some other operations not relevant to this
discussion.) 

For consistency, it seems to me that on the Mac, forward-slashes '/'
ought to be replaced with colons ':' in these functions. The Python code
for these os-specific path modules is in .../Lib/macpath.py and
ntpath.py.

Changing this in macpath.py would allow paths in scripts on either
platform to be always be written using Posix-style forward-slashes and
the norm* functions could be used to convert them to the proper
platform-specific format on either platform. This would be helpful in
writing scripts that could be run unchanged on multiple platforms,
because it would allow path strings in them to be written in a uniform
way. 

It would be an easy modification to make. However it would not be
strictly backwards-compatible because forward-slashes are legal in
filenames on classic MacOS (don't know about OS X), so perhaps that is
why the functions currently leave forward-slashes in path strings alone
on Macintosh. 

Comments?

Since I am still very much a Pythonewbie, excuse me if this is a dumb
suggestion or I have missed something obvious.

Best,
Martin