Open zzzkorn opened 3 years ago
Thanks for the contribution, but I think this could break existing data that just happens to have an apostrophe before a number.
Only the number after the '
at the end of the line is taken into account. We can also use a less common separator.
For example:
x = PrettyTable()
x.field_names = ["Country'500 '30", "Capital", "is_russia", "that's mine"]
+--------------------------------+---------+-----------+-------------+
| Country'500 | Capital | is_russia | that's mine |
+--------------------------------+---------+-----------+-------------+
+--------------------------------+---------+-----------+-------------+
We have no idea what characters people are using in their data.
Would you like to propose an alternative API that doesn't involve interpreting user data?
How about an API like x.set_widths([50, None, ....])
?
And/or add a width
parameter to add_column
and/or add_rows
?
How would it handle data that is longer than the requested width? Cropping the data? Or is it a minimum width?
Changes would require unit tests to cover different use cases, plus documentation in README and docstrings.
(See also https://github.com/jazzband/prettytable/issues/116.)
Ok, I'll take care of the x.set_widths()
method implementation and related tasks.
Merging #126 (37440e0) into master (0a8f5b9) will increase coverage by
0.57%
. The diff coverage is100.00%
.
@@ Coverage Diff @@
## master #126 +/- ##
==========================================
+ Coverage 91.07% 91.65% +0.57%
==========================================
Files 3 3
Lines 1703 1809 +106
==========================================
+ Hits 1551 1658 +107
+ Misses 152 151 -1
Flag | Coverage Δ | |
---|---|---|
GHA_Ubuntu | 91.65% <100.00%> (+0.57%) |
:arrow_up: |
GHA_Windows | 91.65% <100.00%> (+0.57%) |
:arrow_up: |
GHA_macOS | 91.65% <100.00%> (+0.57%) |
:arrow_up: |
Flags with carried forward coverage won't be shown. Click here to find out more.
Impacted Files | Coverage Δ | |
---|---|---|
src/prettytable/prettytable.py | 87.63% <100.00%> (+0.34%) |
:arrow_up: |
tests/test_prettytable.py | 100.00% <100.00%> (ø) |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update 0a8f5b9...37440e0. Read the comment docs.
How does this work with min_width
and max_width
for the whole table?
They're documented in the docstring, but not the README: https://github.com/jazzband/prettytable/pull/98/files
I'd guess these column min widths should override the table one? Some tests mixing would be useful.
Ok i will test this
The _compute_widths() method subtracts the column width, taking into account the minimum and maximum widths. This width is started with the columns_min_width and the maximum value is taken.
Set the length of each column with a separator
'
. For example: