Skip to content

Instantly share code, notes, and snippets.

@jfly
Created August 10, 2019 14:12
Show Gist options
  • Save jfly/a2e2c01e0d86f2f8235f6c1ef9898637 to your computer and use it in GitHub Desktop.
Save jfly/a2e2c01e0d86f2f8235f6c1ef9898637 to your computer and use it in GitHub Desktop.
from cli_helpers.tabular_output import TabularOutputFormatter
formatter = TabularOutputFormatter(format_name='simple')
headers = ("Column A", "Column B")
so_much_b_data = "\n".join(str(i)*50 for i in range(10))
data = [ ("some a data", so_much_b_data) ]
format = "ascii"
print("\n".join(list(formatter.format_output(data, headers, format))))
@jfly
Copy link
Author

jfly commented Aug 10, 2019

When I run this, I see the following:

image

(note that the 9s are truncated, rather than showing all 50 of them)

https://cli-helpers.readthedocs.io/en/stable/api.html#cli_helpers.tabular_output.preprocessors.truncate_string says:

Truncate very long strings. Only needed for tabular representation, because trying to tabulate very long data is problematic in terms of performance, and does not make any sense visually.

This feels pretty weird to me... I think they might be right about long strings with no newlines, but long that aren't actually very wide but have a lot of newlines in them instead seem pretty reasonable to me...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment