期盼死亡的小丑 发表于 2018-8-7 12:39:04

Python prettytable模块

Python 2.6.6 (r266:84292, Jul 23 2015, 15:22:56)  
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      |
  
+-----------+------+------------+-----------------+
  
>>>
页: [1]
查看完整版本: Python prettytable模块