python - linux下用print输出中文一直是乱码该如何解决
PHP中文网
PHP中文网 2017-04-18 09:58:36
0
3
718
PHP中文网
PHP中文网

认证高级PHP讲师

reply all(3)
小葫芦

Print dict and tuple are both displayed in unicode code. If you print a single element under dict or tuple, it will be displayed in normal Chinese.
In addition, adding u in front of the string indicates that the string is in unicode format
You can post your code to see how it is printed.

# -*- coding: utf8 -*-
tuple_d=("你好","abc",123)
print tuple_d
print tuple_d[0]

dic={"name":"张三","age":14}
print dic
print dic["name"]

print "张三"
print u"\u5f00\u59cb"

Output in sequence
('xe4xbdxa0xe5xa5xbd', 'abc', 123)
Hello
{'age': 14, 'name': 'xe5xbcxa0xe4xb8x89'}
Zhang San
Zhang San
Start

迷茫

It seems that what you printed is a tuple

Try printing the string directly, it should be able to display what you want

大家讲道理

Try it like this

import json
print json.dumps("你需要打印的字符串或字典或元组或数组",encoding='utf-8',ensure_ascii=False)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!