本文介绍了如何将ASCII十六进制代码的路径转换为等效的ASCII字母?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Python中使用以下路径:

I am trying to use the following path in Python:

/home/user/Music/library/1-02%2520Maralito.mp3

文件名是:"1-02 Maralito.mp3"

因此该空间正在转换为代码%2520 ,我不知道它代表什么.

So the space is being converted to the code %2520, which I do not know what represents.

我在Ubuntu上使用Rhythmbox API,但无法在Python中转换该值.有什么建议吗?

I am using Rhythmbox API on Ubuntu, and I can't convert the value back in Python. Any suggestions?

推荐答案

此字符串已被URL编码两次. %25代表%字符.解码%25所得的%20表示空格.

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(在Python 2中仅为urllib.unquote)解码%编码,您将需要对其解码两次:

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)))

这篇关于如何将ASCII十六进制代码的路径转换为等效的ASCII字母?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 06:44