是否有将文件uri映射到os.path的便捷方法? [英] Is there a convenient way to map a file uri to os.path?

查看:121
本文介绍了是否有将文件uri映射到os.path的便捷方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个我无法控制的子系统坚持以uri的形式提供文件系统路径.是否有一个python模块/函数可以以独立于平台的方式将此路径转换为文件系统期望的适当形式?

A subsystem which I have no control over insists on providing filesystem paths in the form of a uri. Is there a python module/function which can convert this path into the appropriate form expected by the filesystem in a platform independent manner?

推荐答案

使用

Use urllib.parse.urlparse to get the path from the URI:

import os
from urllib.parse import urlparse
p = urlparse('file://C:/test/doc.txt')
final_path = os.path.abspath(os.path.join(p.netloc, p.path))

这篇关于是否有将文件uri映射到os.path的便捷方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆