How to remove %20 from the file path?

依然范特西╮ 提交于 2019-12-12 07:18:50

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!