-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
configure_stream.py
executable file
·42 lines (30 loc) · 997 Bytes
/
configure_stream.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
"""
.. codeauthor:: Tsuyoshi Hombashi <tsuyoshi.hombashi@gmail.com>
"""
import io
import pytablewriter
def main():
writer = pytablewriter.MarkdownTableWriter()
writer.table_name = "zone"
writer.headers = ["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 instance writes a table to stdout by default
writer.write_table()
# change the stream to a string buffer to get the output as a string
# you can also get tabular text by using dumps method
writer.stream = io.StringIO()
writer.write_table()
print(writer.stream.getvalue())
# change the output stream to a file
with open("sample.md", "w") as f:
writer.stream = f
writer.write_table()
if __name__ == "__main__":
main()