os.path.join() necessary?
Michael Chermside
mcherm at destiny.com
Thu May 23 09:55:09 EDT 2002
Thomas Guettler
> Is os.path.join() necessary? I use
> absolute_path=dir + "/" + file
> on windows (W2K) without problems.
Michael Hudson:
> Try it on the Mac.
Thomas Guettler
> I would, but have not Mac or MacOSX here.
> Can you try it?
Michael Hudson:
> No, but I can tell you what will happen (in Classic, at least): it
> won't work. MacOS <=9 uses colons as path separators.
I think that Thomas is trying to point out is that the path separator on
Windows is '\' (instead of '/' or ':'). He noticed that the underlying C
libraries (I *think* that's what does it) will silently convert '/' to
'\' for him, (and I think it even takes care of the 'C:' stuff that
Windows wants at the front of the path) so he can avoid the complexity
of having to use os.path.join().
I think it would be a nice feature of a programming language that all
file-and-path names are expressed using '/' within the language and
automatically converted to the platform-appropriate format by the
language itself (and paths obtained from the OS are converted to '/'
format also). Unfortunately, as far as I know, Python is not that
language. I *think* (someone more knowledgable please correct me if I'm
wrong) that "wierd" OSes like VMS (and there's MUCH wierder stuff out
there) don't do this conversion. Unix & friends don't need it, Windows
DOES do the conversion, and I don't know about Macs. But for TRUE
portability, I believe you still have to deal with os.path.join().
-- Michael Chermside
More information about the Python-list
mailing list