Brief introduction
Python outputs the output as a tabular format through the prettytable module, and Python itself is not built-in and requires a separate installation of the third-party library.
Installation
1 pip install prettytable
1 # Source Installation 2 wget https://pypi.python.org/packages/source/P/PrettyTable/prettytable-0.7.2. tar.gz3 tar-zxvf prettytable-0.7.2. tar.gz4python setup.py build5 python setup.py Install
Use
1>>> fromPrettytableImportprettytable2>>> x = prettytable (["name"," Age","Sex"," Money"])3>>> x.align["name"] ="L" #Align left with the name field4>>> x.padding_width = 1#Fill Width5>>> X.add_row (["Xue", 20,"Mans", 1000])6>>> X.add_row (["Chen"21st"Mans", 2000])7>>> X.add_row (["Yang", 22,"Mans", 3000])8>>>Print(x)9+-------+-----+-----+-------+Ten| name | Age | sex | Money | One+-------+-----+-----+-------+ A| Xue | 20 | Mans | 1000 | -| Chen | 21 | Mans | 2000 | -| Yang | 22 | Mans | 3000 | the+-------+-----+-----+-------+
1 fromPrettytableImportprettytable2 3x = prettytable (["City name"," Area","Population","Annual Rainfall"]) 4 5x.align["City name"] ="L"#Left align city names6 7X.padding_width = 1#One space between column edges and contents (default)8 9X.add_row (["Adelaide", 1295, 1158259, 600.5]) Ten OneX.add_row (["Brisbane", 5905, 1857594, 1146.4]) A -X.add_row (["Darwin", 112, 120900, 1714.7]) - theX.add_row (["Hobart", 1357, 205556, 619.5]) - -X.add_row (["Sydney", 2058, 4336374, 1214.8]) - +X.add_row (["Melbourne", 1566, 3806092, 646.9]) - +X.add_row (["Perth", 5386, 1554769, 869.4]) A at - PrintX
Python---prettytable