系统编码顺序:
1, a.encode(sys.stdout.encoding)
2, a.encode(default_string)
sys.stdout.encoding里的值可以用环境变量
PYTHONIOENCODING来影响
例如:
# coding: utf-8
a = u'你好'
print a
print a
相当于
# coding: utf-8
src_file_encoding = 'utf-8'
a = '你好'.decode(src_file_encoding)
stdout_implicit_encoding = sys.stdout.encoding or sys.getdefaultencoding()
print a.encode(stdout_implicit_encoding)
# coding: utf-8
src_file_encoding = 'utf-8'
a = '你好'.decode(src_file_encoding)
stdout_implicit_encoding = sys.stdout.encoding or sys.getdefaultencoding()
print a.encode(stdout_implicit_encoding)