Python 中的Tab自動不起 和 一個還看的格式prettytab

Tab

vim/usr/lib64/python2.6/site-packages/tab.py (sys.path查看Python路徑,把自定義模塊放此)
import sys
import readline
import rlcompleter
import atexit
import os
 
readline.parse_and_bind('tab: complete')
histfile = os.path.join(os.environ['HOME'],'.pythonhistory')
 
try:
       readline.read_history_file(histfile)
except IOError:
       pass
atexit.register(readline.write_history_file,histfile)
 
使用:
import tab

prettytable

下載:

https://code.google.com/p/prettytable/downloads/list

安裝:解壓。cp prettytable.py /usr/lib64/python2.6/site-packages/

                   Chmod+x  /usr/lib64/python2.6/site-packages/ prettytable.py

 

使用:

     

    fromprettytable import  PrettyTable
         >>>print x
+------+-----+-----+
| name | age | job |
+------+-----+-----+
+------+-----+-----+
>>> x.align['name'] = 'l' (是L ,相左對齊,r:右對齊,c:居中)
>>> x.add_row(['wxl','20','IT'])
>>> print x
+------+-----+-----+
| name | age | job |
+------+-----+-----+
| wxl  |  20 | IT |
顯示特定行:
>>> print x.get_string(start=0,end=1)
+------+-----+-----+
| name | age | job |
+------+-----+-----+
| wxl  |  20 | IT |
+------+-----+-----+
  顯示特定列:
>>>print x.get_string(fields=["name"])
        +-----------------+        
        | name            |
        +-----------------+
        | wxl             |
        | qiandancongjian |
        +-----------------+
 排序:
 >>>print x.get_string(sortby='age')
        +-----------------+------------------+-----+
        | name            |       age        | job |
        +-----------------+------------------+-----+
        | wxl             |        20        | IT |
        | qiandancongjian | 2000000000000000 |  IT |
        +-----------------+------------------+-----+
反排:
>>>print x.get_string(sortby='age',reversesort=True)
        +-----------------+------------------+-----+
        | name            |       age        | job |
        +-----------------+------------------+-----+
        | qiandancon

 

         | wxl             |        20        | IT |        
         +-----------------+------------------+-----+

 

        

 

 

 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章