Python PrettyTable module, pythonprettytable
I. Introduction
Python uses the prettytable module to output the output content in a table. python itself is not built-in and requires independent installation of this third-party library.
Ii. Installation
Method 1: pip Installation
>>> pip install PrettyTable
Method 2: source code Installation
wget https://pypi.python.org/packages/source/P/PrettyTable/prettytable-0.7.2.tar.gztar -zxvf prettytable-0.7.2.tar.gzpython setup.py buildpython setup.py install
Iii. Use
>>> 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 |+-------+-----+-----+-------+