by shigemk2

当面は技術的なことしか書かない

TabularOutputFormatterのformat_name

改行

GitHub - dbcli/cli_helpers: Python helpers for common CLI tasks

>>> from cli_helpers.tabular_output import TabularOutputFormatter
>>> headers = ('day', 'temperature')
>>> data = enumerate(('87\n87', '80', '79'), 1)
>>> formatter = TabularOutputFormatter(format_name='github')
>>> for test in formatter.format_output(data, headers):
...   print(test)
...
| day | temperature |
|-----|-------------|
| 1   | 87\n87      |
| 2   | 80          |
| 3   | 79          |
>>> formatter = TabularOutputFormatter(format_name='ascii')
>>> data = enumerate(('87\n87', '80', '79'), 1)
>>> for test in formatter.format_output(data, headers):
...   print(test)
...
+-----+-------------+
| day | temperature |
+-----+-------------+
| 1   | 87\n87      |
| 2   | 80          |
| 3   | 79          |
+-----+-------------+
>>> formatter = TabularOutputFormatter(format_name='simple')
>>> data = enumerate(('87\n87', '80', '79'), 1)
>>> for test in formatter.format_output(data, headers):
...   print(test)
...
  day  temperature
-----  -------------
    1  87
       87
    2  80
    3  79