[PYTHONMAC-SIG] Mac open()

Robin Friedrich friedric@rose.rsoc.rockwell.com
Fri, 21 Jun 1996 08:18:30 -0500


|> I bet it's the Mac pathname syntax.  If a pathname contains a colon,
|> it's *relative* when it starts with a colon, it's *absolute* when
|> it doesn't (when it contains no colon at all, it's always relative).
|> 
|> A pathname of the form HD:dir:subdir:file is an absolute pathname,
|> on volume "HD", folder "dir", subfilder "subdir", file "file".
|> 
|> A pathname of the form ":subdir:file" is a relative pathname,
|> in the current directory, subdirectory "subdir", file "file".
|> 
|> --Guido van Rossum


Thanks for the insights everyone.  I wanted to make my test scripts
as portable as possible to the Mac so I whipped out this little 
routine. Seems to work fine.  Maybe others may find it useful
or suggest improvements?

def mpath(path):
    """Converts a POSIX path to an equivalent Macintosh path

    Won't work for '../../style/paths'. I'm not sure the Mac
    has such a concept."""
    import os, string
    if os.name == 'mac' :
        #I'm on a Mac
        if path[:3] == '../':
            mp = '::'
            path = path[3:]
        elif path[:2] == './':
            mp = ':'
            path = path[2:]
        elif path[0] == '/':
            mp = ''
            path = path[1:]
        else:
            mp = ':'
        pl = string.split(path, '/')
        mp = mp + string.join(pl, ':')
        return mp
    else:
        return path

=================
PYTHONMAC-SIG  - SIG on Python for the Apple Macintosh

send messages to: pythonmac-sig@python.org
administrivia to: pythonmac-sig-request@python.org
=================