使用python轻松导入、筛选和导出表格数据
outputt的Python项目详细描述
outputty是一个简单的python库,可以帮助您导入、筛选 以及导出数据。它由一个主要的Table类和许多 有助于将数据导入或导出到Table或从Table导出数据的插件。
您可以轻松编写自己的插件(请参见 示例)。插件的一些例子有:csv、文本、html和直方图。
安装
简单到执行:
pip install outputty
注意:当pip试图编译所有内容时,outputty依赖于 MySQL-Python包(需要编译),您需要 libmysqlclient的头、编译器和相关的东西。安装在 debian/ubuntu,执行:
apt-get install build-essential libmysqlclient-dev
示例
代码时间!:
>>> from outputty import Table >>> my_table = Table(headers=['name', 'age']) # headers are the columns >>> my_table.append(('Álvaro Justen', 24)) # a row as tuple >>> my_table.append({'name': 'Other User', 'age': 99}) # a row as dict >>> print my_table # a text representation of Table +---------------+-----+ | name | age | +---------------+-----+ | Álvaro Justen | 24 | | Other User | 99 | +---------------+-----+ >>> print 'First row:', my_table[0] # Table is indexable First row: [u'\xc1lvaro Justen', 24] >>> print 'Sum of ages:', sum(my_table['age']) # you can get columns too Sum of ages: 123 >>> my_table.write('csv', 'my-table.csv') # CSV plugin will save its contents in a file >>> # let's see what's in the file... >>> print open('my-table.csv').read() "name","age" "Álvaro Justen","24" "Other User","99" >>> # let's use HTML plugin! >>> print my_table.write('html') # without filename ``write`` will return a string <table> <thead> <tr class="header"> <th>name</th> <th>age</th> </tr> </thead> <tbody> <tr class="odd"> <td>Álvaro Justen</td> <td>24</td> </tr> <tr class="even"> <td>Other User</td> <td>99</td> </tr> </tbody> </table>
Table有很多其他特性。要了解更多(通过示例),请阅读 outputty tutorial 请参阅examples文件夹。享受吧!
新功能
是的,有很多特性需要添加(这只是开始)。如果你 想要贡献,请看我们的 outputty wishlist。
您也可以使用outputty Issue Tracking System on GitHub 报告错误。
贡献
如果您想为本项目做出贡献,请:
- 安装运行pip install -r requirements/development.txt的开发依赖项。
- 执行make test以运行所有测试–请在
推动。
- 要只运行一个测试文件,请执行: nosetests --with-coverage--cover-package outputty tests/test_your-test-file.py
- 试着让测试覆盖率达到100%。
- 使用Test-driven development。
- 使用nvie’s gitflow-学习、阅读 A Successful Git branching model。
- 创建/更新文档(自述文件/文档字符串/手册页)
- 不要编辑README.rst和tutorial.rst,编辑 README-template.rst或tutorial-template.rst替换并运行 make create-docs创建新的README.rst和 tutorial.rst(提交前)。本教程将基于 examples文件夹中的文件。
新插件
如果你想创建一个新的插件来导入/导出 资源,请参阅文件outputty/plugin_*.py作为示例。他们是这样的 简单,请遵循以下步骤:
- 创建名为outputty/plugin_name.py的文件,其中name是 你的插件。
- 在此文件中创建read和/或write函数。这些函数接收
Table对象和可选参数。
- read:应该从参数中指定的资源读取数据并将 此数据位于Table(使用Table.append或Table.extend)。
- write:应该从Table(使用切片对其进行迭代)读取数据 等),并将此数据写入参数中指定的资源。
- 调用插件执行my_table.write('name',optional_parameters...) 或者my_table.read('name',optional_parameters...)(其中name是您的 插件名称)-执行时outputty将调用 outputty.plugin_name.read/outputty.plugin_name.write。
编码和解码
你的插件的read函数必须将所有数据放入Unicode中,并且 插件的write函数将接收一个Table对象,其中包含 Unicode(它不应该改变这一点)。但是如果你需要解码/编码 在插件中执行某些操作之前/之后,可以使用Table.decode() 以及Table.encode()。
贡献者
本软件由 Álvaro Justen但是收到了很多 贡献。衷心感谢:
- Fundação Getúlio Vargas为了让我把时间花在 在上面。
- Douglas Andrade给我看的 textwrap.dedent并编写更清晰的测试。
- Flávio Coelho用于创建直方图和 提出了很多建议。
- Renne Rocha用于通过创建顺序。
- Tatiana Al-Chueyr用于设计和编码 插件api的架构建议(包括 我们正在使用的架构)。
- Flávio Amieiro有很多建议 以及对设计的解释。