python输出Unicode和Str连接的字符串

来源:互联网 发布:c语言猜数游戏 编辑:程序博客网 时间:2024/05/16 23:47

当Unicode和字符串连接输出时,会出现编码错误:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe8 in position 7: ordinal not in range(128)

解决方法:

a=u'Example'utf8string = a.encode("utf-8")  print "验证码:"+utf8string"

原创粉丝点击