神刀安全网

Pytablewriter – A python library to write a table with various formats

pytablewriter

Pytablewriter – A python library to write a table with various formats Pytablewriter – A python library to write a table with various formats Pytablewriter – A python library to write a table with various formats Pytablewriter – A python library to write a table with various formats

Summary

pytablewriter is a python library to write a table in various formats: CSV/HTML/JavaScript/JSON/Markdown/Excel/Pandas/Python/reStructuredText

Features

  • Write a table in various formats:
    • CSV

    • Microsoft Excel TM

    • HTML

    • JavaScript (Definition of a nested list variable)

    • JSON

    • Markdown

    • Pandas (Definition of a DataFrame variable)

    • Python code (Definition of a nested list variable)

    • reStructuredText
      • Grid tables
      • Simple tables
      • CSV table
  • Automatic value formatting
    • Alignment
    • Padding
    • Decimal places of numbers
  • Output to a stream such as a file or the standard output

Examples

Write a Markdown table

import pytablewriter  writer = pytablewriter.MarkdownTableWriter() writer.table_name = "zone" writer.header_list = ["zone_id", "country_code", "zone_name"] writer.value_matrix = [     ["1", "AD", "Europe/Andorra"],     ["2", "AE", "Asia/Dubai"],     ["3", "AF", "Asia/Kabul"],     ["4", "AG", "America/Antigua"],     ["5", "AI", "America/Anguilla"], ]  writer.write_table()
# zone zone_id|country_code|   zone_name ------:|------------|----------------       1|AD          |Europe/Andorra       2|AE          |Asia/Dubai       3|AF          |Asia/Kabul       4|AG          |America/Antigua       5|AI          |America/Anguilla

Rendering result

Pytablewriter – A python library to write a table with various formats

Rendered markdown at GitHub

Write a reStructuredText table (grid tables)

import pytablewriter  writer = pytablewriter.RstGridTableWriter() writer.table_name = "zone" writer.header_list = ["zone_id", "country_code", "zone_name"] writer.value_matrix = [     ["1", "AD", "Europe/Andorra"],     ["2", "AE", "Asia/Dubai"],     ["3", "AF", "Asia/Kabul"],     ["4", "AG", "America/Antigua"],     ["5", "AI", "America/Anguilla"], ]  writer.write_table()
.. table:: zone      +-------+------------+----------------+     |zone_id|country_code|   zone_name    |     +=======+============+================+     |      1|AD          |Europe/Andorra  |     +-------+------------+----------------+     |      2|AE          |Asia/Dubai      |     +-------+------------+----------------+     |      3|AF          |Asia/Kabul      |     +-------+------------+----------------+     |      4|AG          |America/Antigua |     +-------+------------+----------------+     |      5|AI          |America/Anguilla|     +-------+------------+----------------+

Rendering result

zone
zone_id country_code zone_name
1 AD Europe/Andorra
2 AE Asia/Dubai
3 AF Asia/Kabul
4 AG America/Antigua
5 AI America/Anguilla

Write a JavaScript table (variable definition of nested list )

import pytablewriter  writer = pytablewriter.JavaScriptTableWriter() writer.table_name = "zone" writer.header_list = ["zone_id", "country_code", "zone_name"] writer.value_matrix = [     ["1", "AD", "Europe/Andorra"],     ["2", "AE", "Asia/Dubai"],     ["3", "AF", "Asia/Kabul"],     ["4", "AG", "America/Antigua"],     ["5", "AI", "America/Anguilla"], ]  writer.write_table()
var zone = [     ["zone_id", "country_code", "zone_name"],     [1, "AD", "Europe/Andorra"],     [2, "AE", "Asia/Dubai"],     [3, "AF", "Asia/Kabul"],     [4, "AG", "America/Antigua"],     [5, "AI", "America/Anguilla"] ];

Write an Excel table

import pytablewriter  writer = pytablewriter.ExcelTableWriter() writer.open_workbook("sample_single.xlsx")  writer.make_worksheet("zone") writer.header_list = ["zone_id", "country_code", "zone_name"] writer.value_matrix = [     ["1", "AD", "Europe/Andorra"],     ["2", "AE", "Asia/Dubai"],     ["3", "AF", "Asia/Kabul"],     ["4", "AG", "America/Antigua"],     ["5", "AI", "America/Anguilla"], ] writer.write_table()  writer.close()

Output

Pytablewriter – A python library to write a table with various formats

Output excel file ( sample_single.xlsx )

For more information

More examples are available at http://pytablewriter.readthedocs.org/en/latest/pages/examples/index.html

Installation

pip install pytablewriter

Dependencies

Python 2.7+ or 3.3+

Test dependencies

Documentation

http://pytablewriter.readthedocs.org/en/latest/

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » Pytablewriter – A python library to write a table with various formats

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址