[Python-Dev] The path module PEP (original) (raw)
Bob Ippolito bob at redivi.com
Thu Jan 26 01:02:20 CET 2006
- Previous message: [Python-Dev] The path module PEP
- Next message: [Python-Dev] The path module PEP
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Jan 25, 2006, at 3:42 PM, Tony Meyer wrote:
[Ian Bicking]
If it were possible to use .join() for joining paths, I think I wouldn't mind so much. But reusing a string method for something very different seems like a bad idea. So we're left with .joinpath (). Still better than os.path.join() I guess, but only a little. I guess that's why I'm +1 on /. Why does reusing a string method for something very different seem like a bad idea, but reusing a mathematical operator for something very different seem like a good idea? Path's aren't strings, so join () seems the logical choice. (There are also alternatives to "joinpath" if the name is the thing: add(), for example).
join() is already defined for strings, division is not. Different
namespace... just like + is concatenation for list+list, tuple+tuple,
basestring+basestring, but it's addition for numbers...
* Not every platform that Python supports has '/' as the path separator. Windows, a pretty major one, has ''. I have no idea what various portable devices use, but there's a reasonable chance it's not '/'.
I believe all platforms support /; at least Windows and Mac do, in addition to their native separators. This is not strictly true. Using '/' can lead to strange results with Windows, where it gets interpreted as a flag instead. It's not reliable, it's not the path separator that Windows users/developers understand, and it's not the correct (i.e. according to Microsoft) path separator. If by Mac you mean OS X, then that's just another *nix based OS. I'm pretty sure that pre OS X (which isn't supported any more anyway, right?) '/' was not, in fact, supported, and that ":" was required. I also believe it's important to remember that Windows and *nix descendants are not "all platforms".
Mac OS X understands '/' as the separator at the POSIX layer, but ':'
as the path separator at the Carbon API (which is only used in
obscure places from Python). Earlier versions of Mac OS are no
longer supported, and you're right -- they only understood ':' as a
path separator.
If anything, a good shortcut for .joinpath() will at least encourage people to use it, thus discouraging hardcoding of path separators. I expect it would encourage portable paths. I'm not sure that I believe that the reason that people don't type "os.path.join('a', 'b')" is because they are too lazy to type it. However, I don't have any evidence either way, so it could be true.
In many cases, when I know I only care about *nix, I will use 'a/b'
instead of os.path.join because it's just so much more concise and
more obvious.
The only times I use os.path.join are when I don't know if there will
be a trailing slash or not, or if I'm actively trying to make
something cross-platform.
-bob
- Previous message: [Python-Dev] The path module PEP
- Next message: [Python-Dev] The path module PEP
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]