V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
shq1995
V2EX  ›  Python

分享一个自己写的 python 库,也许大家以后有点小用。

  •  
  •   shq1995 · 2015-08-10 13:40:00 +08:00 · 2769 次点击
    这是一个创建于 3183 天前的主题,其中的信息可能已经有所发展或是发生改变。
    仓库地址: https://github.com/Leviathan1995/Pylsy
    希望大家多点star.
    已经添加包管理了,可以直接下载:
    pip install pylsy

    作用就是可以方便在终端中输出表格,类似mysql数据库。
    attributes=["name","age","sex","id","time"] #添加表格的属性
    table=PylsyTable(attributes) #创建表格
    name=["sun","lsy","luna","leviathan"] #属性的值
    age=[20,21,23,25]
    table.AddData("age",age)
    table.AddData("name",name) #添加属性的值
    table.CreateTable() #打印表格


    欢迎star ,fork , 提意见,pull request.
    10 条回复    2015-08-12 12:27:05 +08:00
    shq1995
        1
    shq1995  
    OP
       2015-08-10 13:43:41 +08:00
    暂时还不支持中文,有什么改进的地方,大家尽管提
    21grams
        2
    21grams  
       2015-08-10 20:31:47 +08:00 via Android
    用处不大
    shq1995
        3
    shq1995  
    OP
       2015-08-10 20:36:34 +08:00
    @21grams 有时候你需要终端输出的时候,比较有用,和mysql那个展示一样
    ipconfiger
        4
    ipconfiger  
       2015-08-10 21:57:02 +08:00
    为什么不支持中文?
    @shq1995
    shq1995
        5
    shq1995  
    OP
       2015-08-10 22:05:13 +08:00
    @ipconfiger 因为一个中文的长度是3个,目前还没有对中文进行判断,等实习结束了,回学校了,我会添加中文功能的。
    saber000
        6
    saber000  
       2015-08-12 11:34:11 +08:00
    发了一个pull request来支持中文
    对于列宽的处理,一个供参考的方法是判断字符串的每位是否在string.printable,如果不在则认为是中文,宽度加二
    当然用正则也ok
    shq1995
        7
    shq1995  
    OP
       2015-08-12 11:44:55 +08:00
    @saber000 我测试了,字符类型错误
    shq1995
        8
    shq1995  
    OP
       2015-08-12 11:46:04 +08:00
    @saber000 Python 2.7
    shq1995
        9
    shq1995  
    OP
       2015-08-12 11:48:27 +08:00
    @saber000 并不是中文需要占三个长度位置,而是中文只占一个位置,但它测试出来长度为3
    saber000
        10
    saber000  
       2015-08-12 12:27:05 +08:00
    @shq1995 中文请用Unicode
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5650 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 01:40 · PVG 09:40 · LAX 18:40 · JFK 21:40
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.