In [43]: '%s-%s' % ('中国', u'2323')
---------------------------------------------------------------------------
UnicodeDecodeError Traceback (most recent call last)
/home/gowin/yunfan/Kuaibi/gateway/<ipython-input-43-816b251553ea> in <module>()
----> 1 '%s-%s' % ('中国', u'2323')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 0: ordinal not in range(128)
In [44]: '%s-%s' % (u'中国', '2323')
Out[44]: u'\u4e2d\u56fd-2323'
In [45]: '%s-%s' % ('中国', '2323')
Out[45]: '\xe4\xb8\xad\xe5\x9b\xbd-2323'
In [46]: '%s-%s' % (u'中国', u'2323')
Out[46]: u'\u4e2d\u56fd-2323'
为毛第一个会报错呢??
PS: 遇到这类型的问题怎么做才是最佳的解决方案呢? 就是不知道你的字符串是什么编码,然后你要做连接操作.
---------------------------------------------------------------------------
UnicodeDecodeError Traceback (most recent call last)
/home/gowin/yunfan/Kuaibi/gateway/<ipython-input-43-816b251553ea> in <module>()
----> 1 '%s-%s' % ('中国', u'2323')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 0: ordinal not in range(128)
In [44]: '%s-%s' % (u'中国', '2323')
Out[44]: u'\u4e2d\u56fd-2323'
In [45]: '%s-%s' % ('中国', '2323')
Out[45]: '\xe4\xb8\xad\xe5\x9b\xbd-2323'
In [46]: '%s-%s' % (u'中国', u'2323')
Out[46]: u'\u4e2d\u56fd-2323'
为毛第一个会报错呢??
PS: 遇到这类型的问题怎么做才是最佳的解决方案呢? 就是不知道你的字符串是什么编码,然后你要做连接操作.