问题
I am trying to use the following path in Python:
/home/user/Music/library/1-02%2520Maralito.mp3
The file name is: "1-02 Maralito.mp3"
So the space is being converted to the code %2520, which I do not know what represents.
I am using Rhythmbox API on Ubuntu, and I can't convert the value back in Python. Any suggestions?
回答1:
This string has been URL-encoded twice. The %25
represents a %
character. The %20
resulting from decoding the %25
represents a space.
urllib.parse.unquote
(just urllib.unquote
in Python 2) decodes the %
encoding, and you will want to decode it twice:
t = "/home/user/Music/library/1-02%2520Maralito.mp3"
from urllib.parse import unquote # Python 3
from urllib import unquote # Python 2
print(unquote(unquote(t)))
来源:https://stackoverflow.com/questions/46225615/how-do-i-convert-a-path-in-ascii-hex-code-to-its-equivalent-ascii-letters