Python通过prettytable模块将输出内容如表格方式整齐

Python通过prettytable模块将输出内容如表格方式整齐

[摘要:Python经过prettytable模块将输出内容如表格体式格局划一输出: 起首下载 prettytable模块,下载毗邻:https://pypi.python.org/pypi/PrettyTable 下载后解压, 1:cp prettytable.py /usr/lib/python2.7/dist-packages/pr] 

Python通过prettytable模块将输出内容如表格方式整齐输出:

首先下载prettytable模块,下载连接:https://pypi.python.org/pypi/PrettyTable

下载后解压,

1cp prettytable.py /usr/lib/python2.7/dist-packages/prettytable.py

2chmod a+rx /usr/lib/python2.7/dist-packages/prettytable.py

3

[python]view plaincopy


  1. from prettytable import PrettyTable  
  2. x = PrettyTable(["City name", "Area", "Population", "Annual Rainfall"])  
  3. x.align["City name"] = "l"# Left align city names
  4. x.padding_width = 1# One space between column edges and contents (default)
  5. x.add_row(["Adelaide",1295, 1158259, 600.5])  
  6. x.add_row(["Brisbane",5905, 1857594, 1146.4])  
  7. x.add_row(["Darwin", 112, 120900, 1714.7])  
  8. x.add_row(["Hobart", 1357, 205556, 619.5])  
  9. x.add_row(["Sydney", 2058, 4336374, 1214.8])  
  10. x.add_row(["Melbourne", 1566, 3806092, 646.9])  
  11. x.add_row(["Perth", 5386, 1554769, 869.4])  
  12. print x  


结果

15ea77159b80654e6c053c1cac384405.jpg.jpeg


你可能感兴趣的:(Python通过prettytable模块将输出内容如表格方式整齐)