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

Question

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

Answers 1
Added at 2016-12-22 16:12
Tags
Question

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?

Answers to

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

nr: #1 dodano: 2016-12-22 16:12

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)
Source Show
◀ Wstecz