Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove %20 from the file path?

file:///home/ashu/Music/Collections/randomPicks/ipod%20on%20sep%2009/Coldplay-Sparks.mp3

How can I convert a string like the above to get the normal file path which I can pass to open() function?

like image 310
Bunny Rabbit Avatar asked Nov 27 '22 22:11

Bunny Rabbit


2 Answers

Have a look at url2pathname:

import urllib2

path = urllib2.url2pathname("file:///home/ashu/Music/Collections/randomPicks/ipod%20on%20sep%2009/Coldplay-Sparks.mp3")
like image 162
Alan Haggai Alavi Avatar answered Dec 06 '22 15:12

Alan Haggai Alavi


This is called unquote. Avaiable from urllib.

import urllib
urllib.unquote('%20')
like image 20
Senthil Kumaran Avatar answered Dec 06 '22 15:12

Senthil Kumaran