pytablewriter is a python library to write a table in various formats: CSV/HTML/JavaScript/JSON/Markdown/Excel/Pandas/Python/reStructuredText
Project description
pytablewriter
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
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_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
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pytablewriter-0.2.0.tar.gz
.
File metadata
- Download URL: pytablewriter-0.2.0.tar.gz
- Upload date:
- Size: 35.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e8b02f4bd73250ad8e01c414fa1d2f67157f5e2eba84b7c31ca4a20fb5eb2ac |
|
MD5 | ae5050a62fcb8637fdfe398e971e0136 |
|
BLAKE2b-256 | 3357ba11513c0a3e38b039502db32bd7ba073d7207f3121d2a6ea9607f7d4233 |
File details
Details for the file pytablewriter-0.2.0-py2.py3-none-any.whl
.
File metadata
- Download URL: pytablewriter-0.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 20.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9fdb2f80af22948aef929dda0588b3caeb999cdb1950e11a3d613f42f02739db |
|
MD5 | 19a260f2e4867e84e8e358f75884598c |
|
BLAKE2b-256 | ae1c7bc3231ba560e20c9a2be11cb54c4ad17d7c3d7175a64b8ada3ef78ced2a |