python中的print 怎么打印unicode码

import cmath

import math

import sys

import io

 

print("ax\N{SUPERSCRIPT TWO} + bx +c =0")

----运行的时候会报错

print("ax\N{SUPERSCRIPT TWO} + bx +c =0")

UnicodeEncodeError: 'gbk' codec can't encode character '\xb2' in position 2: illegal multibyte sequence

 

在网上查找添加了后

sys.stdout = io.TextIOWrapper(sys.stdout.buffer, errors = 'replace', line_buffering = True)

打印为:

ax? + bx +c =0

 

怎样才会正确的显示

ax2 + bx +c =0

posted on 2013-10-11 16:27  Duany  阅读(439)  评论(0)    收藏  举报