easier conversion pathToURL possible?
christof hoeke
csad7 at yahoo.com
Tue Jan 7 15:46:15 EST 2003
More information about the Python-list mailing list
Tue Jan 7 15:46:15 EST 2003
- Previous message (by thread): Unicode error: ASCII encoding error. Ordinal not in range(128) ???
- Next message (by thread): Custom statements
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
hi, for a program i need filepaths like "\test\index.html" that might come as input from the command line to be converted to urls like "/test/index.html". (somehow something contrary to what os.path can do to a path..., not to make it os specific but generalize it). also absolute paths like "c:\test\index.html" should be converted to an url like file:///c:/test/index.html. i could not find a solution in the standard library, is there one? the following is the function i wrote for doing this. is there an easier solution to it and does it work for all platforms at all? i could only test this on windows. def pathToURL(path): """ converts a os specific filepath into a standard URL? """ #delete garbage like /./ path = os.path.normpath(path) #use file: protocoll for complete paths with drivenames drive, p = os.path.splitdrive(path) #change possible \ to / url = string.replace(p, "\\", "/") if drive: return "file:///%s%s" % (drive, url) else: return url does this code work on unix and mac at all? thanks a lot! chris
- Previous message (by thread): Unicode error: ASCII encoding error. Ordinal not in range(128) ???
- Next message (by thread): Custom statements
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list