1 #!/usr/bin/env python
2 # -*- coding:utf-8 -*-
3 #Author: ####
4
5 from prettytable import PrettyTable
6 x = PrettyTable(["姓名", "性别", "年龄", "存款"])
7
8 x.align["姓名"] = "1" #以姓名字段左对齐
9 x.padding_width = 1 # 填充宽度
10 x.add_row(["赵一","男", 20, 100000])
11 x.add_row(["钱二","男", 21, 500])
12 x.add_row(["孙三", "男", 22, 400.7])
13 x.add_row(["李四", "男", 23, 619.5])
14 x.add_row(["周五", "男", 24, 1214.8])
15 x.add_row(["吴六", "女", 25, 646.9])
16 x.add_row(["郑七", "女", 26, 869.4])
17 x.add_row(["王七加一", "男", 21, 869.4])
18
19 print(x)
网上有这样一个示例,能够格式化输出中文标题并且不乱码,但是我运行这段代码之后输出的是乱码标题
是因为python版本不对的问题吗?python2.7环境下要怎么设置才能输出中文不乱码?
ps:在jupyter notebook里输出是正常的,在命令行环境下直接运行输出就乱码
python环境如下
My output under pycharm is normal. You can try adding a u in front of the Chinese, such as: