Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
UnicodeEncodeError:&x27;ascii';编解码器可以';t编码字符u'\u25cf';位置24:序号不在Python 2.7中的范围(128)内_Python - Fatal编程技术网

UnicodeEncodeError:&x27;ascii';编解码器可以';t编码字符u'\u25cf';位置24:序号不在Python 2.7中的范围(128)内

UnicodeEncodeError:&x27;ascii';编解码器可以';t编码字符u'\u25cf';位置24:序号不在Python 2.7中的范围(128)内,python,Python,我试图打印ascii字符和string,但出现以下错误: UnicodeEncodeError:“ascii”编解码器无法对位置24处的字符u'\u25cf'进行编码:序号不在范围内(128) 这是我的常量。图标\u黑色\u圆圈 ICON_BLACK_CIRCLE = u'\u25CF' 在这里,我试图用其他字符串打印它 print "{: ^71s}".format(constants.ICON_BLACK_CIRCLE + " - " + errormsg), s = "|

我试图打印
ascii
字符和
string
,但出现以下错误:

UnicodeEncodeError:“ascii”编解码器无法对位置24处的字符u'\u25cf'进行编码:序号不在范围内(128)

这是我的
常量。图标\u黑色\u圆圈

ICON_BLACK_CIRCLE = u'\u25CF'
在这里,我试图用其他字符串打印它

print "{: ^71s}".format(constants.ICON_BLACK_CIRCLE + " - " + errormsg),    
s = "|    |"
print(s)

如何修复此错误?

这就是如何消除此异常的方法

只需将第二个字符串也设为unicode字符串

print u"{: ^71s}".format(constants.ICON_BLACK_CIRCLE + " - " +errormsg)