convert file:// URI to open parameter string in Python 2

152 Views Asked by At

given a URI such as "file:///Volumes/Shared/1-05%20Born%20to%20be%20Wild.m4a". What is the easiest way to convert this to "/Volumes/Shared/1-05 Born to be Wild.m4a" so I could pass it as a parameter to open() or something similar?

1

There are 1 best solutions below

0
On BEST ANSWER

It looks like this should do what you want:

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)