【发布时间】:2019-06-04 13:49:06
【问题描述】:
我正在使用 Python 3.x 并且有一个包含 utf-8 字符的字符串,如下所示:
link='https%3A%2F%2Fwww.google.com'
我现在想将字符串转换为 ascii,使其显示为“https://www.google.com”。我怎样才能做到这一点?我试过了
link.decode('utf-8')
抛出异常:
AttributeError: 'str' object has no attribute 'decode'
有没有一种简单的方法可以简单地将包含 utf-8 字符的字符串解码为纯 ascii 字符?
【问题讨论】:
-
URL 编码和 UTF-8 编码是两个独立的东西。
-
该字符串中没有 UTF-8 字符(纯 ASCII 字符除外,当然技术上 也是 UTF-8 字符,很简单)。
-
感谢您的澄清!
标签: python-3.x utf-8 ascii