from_html fails with tables that use colspan
GoogleCodeExporter opened this issue · comments
What steps will reproduce the problem?
prettytable.from_html('<table><tr><td>one</td><td>two</td></tr><tr><td
colspan="2">three</td></tr></table>')
What is the expected output? What do you see instead?
Ideally I'd hope to see a table that prints to
+---------+---------+
| Field 1 | Field 2 |
+---------+---------+
| one | two |
| three |
+---------+---------+
but I'd settle for
+---------+---------+
| Field 1 | Field 2 |
+---------+---------+
| one | two |
| three | |
+---------+---------+
What I get instead is
Exception: Row has incorrect number of values, (actual) 1!=2 (expected)
What version of the product are you using? On what operating system?
0.7.2 on Ubuntu 13.04
Original issue reported on code.google.com by mged...@gmail.com
on 26 Aug 2013 at 10:46
Thanks for the report and sorry for the slow response time.
I agree that the current behviour is sub-optimal, if only because the cause of
the problem is not very explicit: ideally the exception message should
explicitly identify the use of colspan as the cause of the problem, so a user
is not left scratching their head.
As for the prospect of actually parsing a colspan-using table instead of
failing explicitly, I am not sure how I feel about the first option you
present, i.e.:
+---------+---------+
| Field 1 | Field 2 |
+---------+---------+
| one | two |
| three |
+---------+---------+
Doing this would require a fairly drastic change to the way PrettyTable
represents table contents. The other option would be quicker and easier, and I
think it represents a better trade-off between cost involved and utility
gained, given that I think this is a relatively rare issue (this is the first
report I've received). I'll try to get this into the next release.
Original comment by luke@maurits.id.au
on 9 Sep 2013 at 5:26
Original comment by luke@maurits.id.au
on 9 Sep 2013 at 5:27
- Changed state: Accepted
This is now implemented in trunk. It yields the second kind of table you
suggested, i.e. blank columns after the first column, up to the appropriate
number. Please feel free to test this feature and provide feedback.
Original comment by luke@maurits.id.au
on 7 Oct 2013 at 9:07
- Changed state: Fixed