且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

python将unicode转换为字符串

更新时间:2022-11-09 09:57:48

您正在将字符串 representation 与它的价值。当您打印Unicode字符串时,不会打印 u

You're confusing the string representation with its value. When you print a unicode string the u doesn't get printed:

>>> foo=u'abc'
>>> foo
u'abc'
>>> print foo
abc



更新:



由于您正在处理元组,所以您很难摆脱这种麻烦:您必须打印元组的成员

>>> foo=(u'abc',)
>>> print foo
(u'abc',)
>>> # If the tuple really only has one member, you can just subscript it:
>>> print foo[0]
abc
>>> # Join is a more realistic approach when dealing with iterables:
>>> print '\n'.join(foo)
abc