标签:
Python通过prettytable模块将输出内容如表格方式整齐输出,python本身并不内置,需要独立安装该第三方库。
方式一:pip安装
>>> pip install PrettyTable
方式二:源码安装
wget https://pypi.python.org/packages/source/P/PrettyTable/prettytable-0.7.2.tar.gz tar -zxvf prettytable-0.7.2.tar.gz python setup.py build python setup.py install
>>> from prettytable import PrettyTable >>> x = PrettyTable(["name", "age", "sex", "money"]) >>> x.align["City name"] = "l" >>> x.padding_width = 1 >>> x.add_row(["wang",20, "man", 1000]) >>> x.add_row(["alex",21, "man", 2000]) >>> x.add_row(["peiqi",22, "man", 3000]) >>> print(x) +-------+-----+-----+-------+ | name | age | sex | money | +-------+-----+-----+-------+ | wang | 20 | man | 1000 | | alex | 21 | man | 2000 | | peiqi | 22 | man | 3000 | +-------+-----+-----+-------+
标签:
原文地址:http://www.cnblogs.com/wang-yc/p/5635296.html