How Do I Convert A Path In Ascii Hex Code, To Its Equivalent Ascii Letters?
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 %2
Solution 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 3from urllib import unquote # Python 2print(unquote(unquote(t)))
Post a Comment for "How Do I Convert A Path In Ascii Hex Code, To Its Equivalent Ascii Letters?"