prettytable
prettytable copied to clipboard
Option to truncate column headers
Sometimes column headers are (much) longer than the column data. An option to ignore the width of the header itself would be nice to have.
Please could you give some example input that causes this? And show the current output and what sort of thing you're after.
#!/usr/bin/python3
from prettytable import PrettyTable
t = PrettyTable()
t.field_names = ['A Field Name', 'B Field Name', 'D Field Name', 'E Field Name', 'F Field Name', 'G Field Name', 'H Field Name', 'I Field Name', 'J Field Name', 'K Field Name', 'L Field Name', 'M Field Name']
# t.field_names = ['A', 'B', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M']
t.add_row([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
print(t)
# Current:
# +--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
# | A Field Name | B Field Name | D Field Name | E Field Name | F Field Name | G Field Name | H Field Name | I Field Name | J Field Name | K Field Name | L Field Name | M Field Name |
# +--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
# | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
# +--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
# Desired:
# +---+---+---+---+---+---+---+---+---+---+----+----+
# | A | B | D | E | F | G | H | I | J | K | L | M |
# +---+---+---+---+---+---+---+---+---+---+----+----+
# | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
# +---+---+---+---+---+---+---+---+---+---+----+----+
@OlafvdSpek do you think it would be appropriate to add the option to truncate headers? Maybe something like
t.truncate_header['A Field Name'] = True
?
Yes, but I'm not sure about the hardest part, the naming. use_header_widths
, ignore_header_widths
, something else?
@hugovk I can handle adding this feature. Do you have any input on what a good option name might be?