【发布时间】:2021-11-30 10:43:24
【问题描述】:
如何转换
str1 = 'Sabrau00AE Family Size Roasted Pine Nut Hummus - 17 oz'
到
final_str = 'Sabra® Family Size Roasted Pine Nut Hummus - 17oz'` in python3.
我试过了:
str1.encode('utf-8') html.unescapestr1.encode('utf-8').decode('unicode_escape')str1.encode('utf-8').decode('ascii')
但没有运气。
isinstance(str1,str) 的输出是True
str1.encode('utf=8') 的输出是字节字符串 b'Sabrau00AE Family Size Roasted Pine Nut Hummus - 17 oz'
我也导入了charade,但是编码和解码功能出错。
AttributeError: 'str' object has no attribute 'decode'
AttributeError: 'str' object has no attribute 'encoding'
【问题讨论】:
标签: python utf-8 ascii decode encode