Tab
vim/usr/lib64/python2.6/site-packages/tab.py (sys.path View python path, put the custom module in this) import Sysimport Readlineimport Rlcompleterimport atexitimport os readline.parse_and_bind (' tab:complete ') Histfile = Os.path.join (os.environ[' HOME ') , '. Pythonhistory ') try:readline.read_history_file (histfile) except IOError:passatexit.register (readline.write _history_file,histfile) using: Import tab
Prettytable
Download:
Https://code.google.com/p/prettytable/downloads/list
Install: Unzip. CP prettytable.py/usr/lib64/python2.6/site-packages/
chmod+x/usr/lib64/python2.6/site-packages/prettytable.py
Use:
fromprettytable import prettytable >>>print x+------+-----+-----+| name | age | job |+------+-----+-----+ +------+-----+-----+>>> x.align[' name '] = ' l ' (is l , opposite alignment, R: Right-aligned, C: centered) >>> x.add_row ([' Wxl ', ' ' + ', ' IT ']) >>> print x+------+-----+-----+| name | age | job |+------+-- ---+-----+| wxl | 20 | it | display a specific line: >>> print x.get_ String (start=0,end=1) +------+-----+-----+| name | age | job |+------+-----+----- +| wxl | 20 | it |+------+-----+-----+ Display specific columns:>>> Print x.get_string (fields=["name"])
+-----------------+ | name | +-----------------+ | wxl | | qiandancongjian | +-----------------+ Sort: >>>print x.get_string ( Sortby= ' age ') +-----------------+------------------+-----+ | name | age | job | +-----------------+------------------+-----+ | wxl | 20 | IT | | qiandancongjian | 2000000000000000 | it | +----------------- +------------------+-----+ Reverse: >>>print x.get_string (sortby= ' age ', reversesort=true) +-----------------+------------------+-----+ | name | age | job | +-----------------+------------------+-----+ | Qiandancon
| WXL | 20 | IT | +-----------------+------------------+-----+
The tab in Python does not automatically start and a still-see format prettytab