前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Python prettytable模

Python prettytable模

作者头像
py3study
发布2020-01-06 15:27:45
8070
发布2020-01-06 15:27:45
举报
文章被收录于专栏:python3

Python  prettytable模块 

Python通过prettytable模块将输出内容

如表格方式整齐输出:

代码语言:javascript
复制
首先下载prettytable模块,
下载连接:https://pypi.python.org/pypi/PrettyTable
下载后解压: 
wget https://pypi.python.org/packages/source/P/PrettyTable/prettytable-0.7.2.tar.gz#md5=a6b80afeef286ce66733d54a0296b13b
tar zxf prettytable-0.7.2.tar.gz 
1:cp prettytable.py  /usr/lib/python2.6/site-packages/
2:chmod a+rx  /usr/lib/python2.6/site-packages/prettytable.py
代码语言:javascript
复制
Python 2.6.6 (r266:84292, Jul 23 2015, 15:22:56) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from prettytable import PrettyTable  
>>> 
>>> x = PrettyTable(["City name", "Area", "Population", "Annual Rainfall"]) 
>>> x.align["City name"] = "l"# Left align city names
>>> x.padding_width = 1# One space between column edges and contents (default)
>>> x.add_row(["Brisbane",5905, 1857594, 1146.4]) 
>>> x.add_row(["Hobart", 1357, 205556, 619.5])  
>>> print x 
+-----------+------+------------+-----------------+
| City name | Area | Population | Annual Rainfall |
+-----------+------+------------+-----------------+
| Brisbane  | 5905 |  1857594   |      1146.4     |
| Hobart    | 1357 |   205556   |      619.5      |
+-----------+------+------------+-----------------+
>>>
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/09/16 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档