37,719
社区成员
发帖
与我相关
我的任务
分享
#encoding:utf8
import sys
import locale
s = u'字符串'
s.encode('utf8')
s.encode('gbk')
s = u'string %s' % s
print sys.getdefaultencoding()
print locale.getdefaultlocale()
print type(s)
print (s)
ascii
('en_US', 'UTF8')
<type 'unicode'>
string 字符串
ascii
('en_US', 'UTF8')
<type 'unicode'>
Traceback (most recent call last):
File "/tmp/test.py", line 12, in <module>
print (s)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 7-12: ordinal not in range(128)