oogl-import / prettytable

Automatically exported from code.google.com/p/prettytable
Other
0 stars 0 forks source link

Changing fields_names does not recompute the column widths #8

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

import prettytable
pt = prettytable.PrettyTable('a b c'.split())
pt.add_row([1,2,3])
pt.add_row([4,5,6])

pt.printt()  # Works as expected

# Now let's change the headers...

pt.field_names = "aaa bbb ccc".split()
pt.printt()  # oops!

# This gets printed:
+---+---+---+
| aaa | bbb | ccc |
+---+---+---+
| 1 | 2 | 3 |
| 4 | 5 | 6 |
+---+---+---+

# Setting the headers a second time fixes this issue:
pt.field_names = "aaa bbb ccc".split()
pt.printt()

+-----+-----+-----+
| aaa | bbb | ccc |
+-----+-----+-----+
|  1  |  2  |  3  |
|  4  |  5  |  6  |
+-----+-----+-----+

I believe this happens because self._recompute_widths() is called before 
setting the new value for _field_names.

Tested with:
* prettytable SVN revision 36
* Python 2.6

Original issue reported on code.google.com by denilsonsa on 17 Jan 2011 at 5:51

GoogleCodeExporter commented 8 years ago
Fixed in trunk.  Thank you for reporting and sorry for the delay!

Original comment by luke@maurits.id.au on 9 Jul 2011 at 7:50