这个包被放到了GoogleCode上,所以你可能没听说过。GoogleCode现在就像西伯利亚一样荒凉。
尽管它被流放到了一个冰天雪地、荒无人烟的地方,prettytable
仍旧是最棒的结构化输出的库,它能在终端或浏览器里构建良好的输出。因此,如果你正在用 IPython Notebook的新插件,建议你用prettytable
来代替__repr__
进行HTML输出。
prettytable 安装
1 |
pip install prettytable |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#coding:utf-8 import requests,re,sys,os reload(sys) sys.setdefaultencoding('utf-8') import csv from prettytable import PrettyTable table = PrettyTable(["key", "search","cate"]) with open('1.csv') as f: for line in f: row = line.split(',') key = row[0] search = int(row[1]) # 一定要转换成数字 不然排序不生效 cate = row[2] table.add_row([key, search,cate]) print table.get_string(sortby="search", reversesort=True) |