如何编码或解码ascii编解码器?

2024-05-16 01:47:11 发布

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

   The string that could not be encoded/decoded was: 熔树脂温度(℃)

   'ascii' codec can't encode characters in position 0-4: ordinal not in range(128)

我试图编码ascii字符,但我得到了错误。我试过了

^{pr2}$

什么都没用。在


Tags: theinstringthatasciinotbe温度
1条回答
网友
1楼 · 发布于 2024-05-16 01:47:11

要转换为unicode:

In [1]: str1 = '熔树脂温度(℃)'

In [2]: print str1
熔树脂温度(℃)

In [3]: str1
Out[3]: '\xe7\x86\x94\xe6\xa0\x91\xe8\x84\x82\xe6\xb8\xa9\xe5\xba\xa6(\xe2\x84\x83)'

In [4]: unicode_str1 = str1.decode('UTF-8')

In [5]: print unicode_str1
熔树脂温度(℃)

In [6]: unicode_str1
Out[6]: u'\u7194\u6811\u8102\u6e29\u5ea6(\u2103)'

相关问题 更多 >