WTF?打印unicode字符串 [英] WTF? Printing unicode strings

查看:78
本文介绍了WTF?打印unicode字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

>>> u''\xbd''

u''\xbd''

print _
Traceback(最近一次调用最后一次):

文件"< stdin>",第1行,在?

UnicodeEncodeError:''ascii''编解码器无法编码字符u''\ xbd''在

位置0:序数不在范围内(128)


解决方案

Ron Garret写道:

u''\ xbd''u''\xbd''print _ Traceback(最近一次调用最后一次):
文件"< stdin>",第1行,在?
UnicodeEncodeError:''ascii' '编解码器不能编码字符u''\ xbd''在
位置0:序数不在范围内(128)




不确定是否这对你很有帮助,但是:
u''\xbd''
u''\xdd''print _



Ron Garret写道:

u''\xbd' 'u''\xbd''print _


Traceback(最近一次调用最后一次):
文件"< stdin>",第1行,在?
UnicodeEncodeError:''ascii''编解码器无法在
位置0编码字符u''\xbd'':ordinal不在范围内(128)




所以你的机器上的标准输出是ascii,你不明白为什么你这个b $ b不能打印出非ascii unicode字符呢? wtf


< / F>


在文章< ma ******* ********************************@蟒蛇。 org>,

Fredrik Lundh< fr ***** @ pythonware.com>写道:

Ron Garret写道:

> u''\xbd''


u''\xbd''

> print _


Traceback(最近一次调用最后一次):
文件"< stdin>",第1行,在?
UnicodeEncodeError:''ascii''编解码器可以不要在
位置0编码字符u''\ xbd'':ordinal不在范围内(128)



所以你机器上的stdout是ascii,而你不明白你为什么不打印非ascii unicode角色呢? wtf?

< / F>




我忘了提及:

sys.getdefaultencoding()
''utf-8''print u''\xbd''
Traceback(最近一次调用最后一次) :

文件"< stdin>",第1行,在?

UnicodeEncodeError:''ascii''编解码器不能编码字符u'' \\ _xbd''在

位置0:序数不在范围内(128)



>>> u''\xbd''
u''\xbd''

print _ Traceback (most recent call last):
File "<stdin>", line 1, in ?
UnicodeEncodeError: ''ascii'' codec can''t encode character u''\xbd'' in
position 0: ordinal not in range(128)


解决方案

Ron Garret wrote:

u''\xbd'' u''\xbd'' print _ Traceback (most recent call last):
File "<stdin>", line 1, in ?
UnicodeEncodeError: ''ascii'' codec can''t encode character u''\xbd'' in
position 0: ordinal not in range(128)



Not sure if this really helps you, but:

u''\xbd'' u''\xbd'' print _ ?



Ron Garret wrote:

u''\xbd'' u''\xbd'' print _


Traceback (most recent call last):
File "<stdin>", line 1, in ?
UnicodeEncodeError: ''ascii'' codec can''t encode character u''\xbd'' in
position 0: ordinal not in range(128)



so stdout on your machine is ascii, and you don''t understand why you
cannot print a non-ascii unicode character to it? wtf?

</F>


In article <ma***************************************@python. org>,
Fredrik Lundh <fr*****@pythonware.com> wrote:

Ron Garret wrote:

> u''\xbd''


u''\xbd''

> print _


Traceback (most recent call last):
File "<stdin>", line 1, in ?
UnicodeEncodeError: ''ascii'' codec can''t encode character u''\xbd'' in
position 0: ordinal not in range(128)



so stdout on your machine is ascii, and you don''t understand why you
cannot print a non-ascii unicode character to it? wtf?

</F>



I forgot to mention:

sys.getdefaultencoding() ''utf-8'' print u''\xbd'' Traceback (most recent call last):
File "<stdin>", line 1, in ?
UnicodeEncodeError: ''ascii'' codec can''t encode character u''\xbd'' in
position 0: ordinal not in range(128)



这篇关于WTF?打印unicode字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆