def path2url(path): "Convert a pathname to a file URL" from urllib.parse import urljoin from urllib.request import pathname2url return urljoin('file:', pathname2url(path))