python 编码问题

>>> a="中"

>>> a
'\xe4\xb8\xad'
>>> b=a.decode()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 0: ordinal not in range(128)
>>> b=a.encode("utf-8")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 0: ordinal not in range(128)
>>> b=a.decode("utf-8")
>>> b
u'\u4e2d'
>>> a=u"中"
>>> a
u'\u4e2d'

怎么样才能出来中文字?

猜你喜欢

转载自www.cnblogs.com/hsdchenliyang/p/9210995.html