[Tutor] Mac to UNIX and back again (what to do about path)

Remco Gerlich scarblac@pino.selwerd.nl
Thu, 12 Jul 2001 08:55:07 +0200


On  0, Wesley Chun <wesc@deirdre.org> wrote:
> In John's reply, he indicated an intelligent way to join pathnames
> into a singleproperly-delimited string like this:
> 
> >>path=os.path.join("myfolder", "mysubfolder", "myfile")
> 
> I think that he meant using os.sep and a sequence instead:
> 
> path=os.sep.join(["myfolder", "mysubfolder", "myfile"])

No, he meant the very useful function os.path.join(), which is more
intelligent than a simple string join.

For instance, it ignores empty arguments, and if one of the arguments starts
at the root dir again ("/home", "scarblac", "/home") it throws away the
arguments before that. If one of the arguments ends with a path seperator, a
new one isn't inserted.

The documentation talks about inserting a /, but it actually means inserting
whatever seperator is relevant on the current platform.

-- 
Remco Gerlich