Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing fields_names does not recompute the column widths #8

Closed
GoogleCodeExporter opened this issue Sep 1, 2015 · 1 comment
Closed

Comments

@GoogleCodeExporter
Copy link

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
Copy link
Author

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

  • Changed state: Fixed

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

No branches or pull requests

1 participant