转换file:// URI以在Python 2中打开参数字符串

时间:2016-12-22 15:46:30

标签: uri python-2.x

给出诸如"文件:///Volumes/Shared/1-05%20Born%20to%20be%20Wild.m4a"之类的URI。什么是最简单的方法将其转换为" / Volumes / Shared / 1-05天生就是Wild.m4a"所以我可以将它作为参数传递给open()或类似的东西?

1 个答案:

答案 0 :(得分:0)

看起来这应该做你想要的:

import urllib2

url = "file:///Volumes/Shared/1-05%20Born%20to%20be%20Wild.m4a"
if url[0:7] == 'file://':
    cleaned_url = url[7:]
    cleaned_url = urllib2.unquote(url_string)