试图破解国际化的u

2024-04-19 05:30:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我现在有一个域名列表,其中一些是国际化的。你知道吗

例如,一个以xn--nqv7f.com结尾,但我希望它显示为机构.com

我试着把它编码成asciiutf-8,但我似乎无法让控制台或我的网站这样打印它。我使用的是python3.5

'xn--nqv7f.com'.decode('utf-8')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'decode'

当我尝试这个的时候,我只得到这个

'xn--nqv7f.com'.encode("idna")
b'xn--nqv7f.com'

Tags: commost编码列表机构网站结尾ascii