[Python-3000] Path Reform: Get the ball rolling

Talin talin at acm.org
Thu Nov 2 18:53:53 CET 2006


Ronald Oussoren wrote:
> 
> On Nov 2, 2006, at 5:21 PM, Paul Moore wrote:
> 
>> On 11/1/06, Mike Orr <sluggoster at gmail.com> wrote:
>>> [...] especially since both Mac and
>>> Windows do the right thing with "/", "..", and "." now.
>>
>> Not always:
>>
>> D:\Data>dir C:/
>> Invalid switch - "".
> 
> And on Mac this depends on the API you use, if you use the Carbon API's 
> you still have to use colons as directory separators (and the OS does 
> the correct translation for you, which is why you can still have a file 
> named "a/b" in the Finder).

I think you folks are missing the point here - of *course* different 
platforms have different interpretations of path separators.

But that's not what we're talking about here - we are talking about the 
behavior of os.path.normpath().

Look, people have been writing cross-platform Python code for years. How 
is this possible when different platforms have such a radical 
interpretation of path strings? The answer is that Python's path 
manipulation functions are *better* than what the underlying platform 
supplies. os.path doesn't just slavishly copy the semantics of the local 
filesystem, it is far more generous (and more useful).

Using os.path.normpath(), one is able to manipulate path strings in a 
cross-platform way. So if say:

    os.path.normpath( os.path.join( __file__, "../../lib" )

...what I get on both Win32, Linux and OSX (I can't speak for any other 
platform) is exactly the same semantics.

And as far as things like os.pardir goes - you can't put 'os.pardir' in 
a configuration file! There are *lots* of applications where you want to 
share data files across platforms, and not have to revise the path 
strings every time you migrate between Unix and Win32.

In fact, I'll tell you a little secret about Win32 applications - 
although "officially" the path separator for Win32 is backslash, there 
are so many Unix and cross-platform programs ported to Win32 that a 
larger percentage of the programs available on Win32 accept paths in 
either format.

So lets not get bogged down in the strange quirks of how a particular 
platform interprets paths - I am much more interested in being able to 
combine paths together in an intuitive way, and have it "just work" on 
all platforms. And that includes path strings read from config files, 
not just path objects.

-- Talin


More information about the Python-3000 mailing list