码迷,mamicode.com
首页 > 编程语言 > 详细

Python 中的Tab自动不起 和 一个还看的格式prettytab

时间:2015-05-12 19:16:21      阅读:212      评论:0      收藏:0      [点我收藏+]

标签: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 |        
         +-----------------+------------------+-----+

 

        

 

 

 


Python 中的Tab自动不起 和 一个还看的格式prettytab

标签:prettytab

原文地址:http://qiandan.blog.51cto.com/9452609/1650572

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!