Python prettytable模块
2016-03-17 22:56
513 查看
Python prettytable模块
Python通过prettytable模块将输出内容如表格方式整齐输出:
Python通过prettytable模块将输出内容如表格方式整齐输出:
首先下载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
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 | +-----------+------+------------+-----------------+ >>>
相关文章推荐
- Python动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 使用Python生成Excel格式的图片
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- Python中zip()函数用法举例
- Python中map()函数浅析
- Python将excel导入到mysql中
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定
- FREEBASIC 编译可被python调用的dll函数示例
- Python 七步捉虫法