a='0123456789'
c='#Eg�'
b1=bytes.fromhex(a).decode("utf8",errors='ignore') #####使用 errors='ignore' 忽略了无法编码的字符
b=bytes.fromhex(a).decode("utf8",errors='replace') ######使用errors='replace'将无法编码的字符用问好代替
b2=bytes.fromhex(a).decode('latin-1',errors='xmlcharrefreplace')####使用errors='xmlcharrefreplace'将无法编码的内容替换成XML实体
print(type(a))
print(type(b))
print(b1)
print(b)
print(b2)
if c==b:
print('nice')
else:
print('error')
结果:
<class 'str'>
<class 'str'>
#Eg
#Eg�
#Eg‰
nice