如何从文件路径中删除%20?

时间:2011-01-02 04:24:33

标签: python filepath

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

如何转换上述字符串以获取可以传递给open()函数的普通文件路径?

2 个答案:

答案 0 :(得分:16)

查看url2pathname

import urllib2

path = urllib2.url2pathname("file:///home/ashu/Music/Collections/randomPicks/ipod%20on%20sep%2009/Coldplay-Sparks.mp3")

答案 1 :(得分:10)

这称为unquote。可以从urllib获得。

import urllib
urllib.unquote('%20')