问题
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?
回答1:
Have a look at url2pathname:
import urllib2
path = urllib2.url2pathname("file:///home/ashu/Music/Collections/randomPicks/ipod%20on%20sep%2009/Coldplay-Sparks.mp3")
回答2:
This is called unquote. Avaiable from urllib.
import urllib
urllib.unquote('%20')
来源:https://stackoverflow.com/questions/4577120/how-to-remove-20-from-the-file-path