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

argument max_width doesn't work #272

Open
aisviper opened this issue Jan 15, 2024 · 0 comments
Open

argument max_width doesn't work #272

aisviper opened this issue Jan 15, 2024 · 0 comments

Comments

@aisviper
Copy link

aisviper commented Jan 15, 2024

I try this code

x = PrettyTable(max_width=10)
x.field_names = ["City name", "Area", "Population", "Annual Rainfall"]
x.add_row(["Adelaide", 1295, 1158259, 600.5])
x.add_row(["Brisbane", 5905, 185759411111111111111111111, 1146.4])
x.add_row(["Darwin", 112, 120900, 1714.7])
x.add_row(["Hobart", 1357, 205556, 619.5])
x.add_row(["Sydney", 2058, 4336374, 1214.8])
x.add_row(["Melbourne", 1566, 3806092, 646.9])
x.add_row(["Perth", 5386, 1554769, 869.4])

print(x)

and get:

+-----------+------+-----------------------------+-----------------+
| City name | Area |          Population         | Annual Rainfall |
+-----------+------+-----------------------------+-----------------+
|  Adelaide | 1295 |           1158259           |      600.5      |
|  Brisbane | 5905 | 185759411111111111111111111 |      1146.4     |
|   Darwin  | 112  |            120900           |      1714.7     |
|   Hobart  | 1357 |            205556           |      619.5      |
|   Sydney  | 2058 |           4336374           |      1214.8     |
| Melbourne | 1566 |           3806092           |      646.9      |
|   Perth   | 5386 |           1554769           |      869.4      |
+-----------+------+-----------------------------+-----------------+

if i change code to:

x = PrettyTable(["City name", "Area", "Population", "Annual Rainfall"], max_width=10)
x.add_row(["Adelaide", 1295, 1158259, 600.5])
x.add_row(["Brisbane", 5905, 185759411111111111111111111, 1146.4])
x.add_row(["Darwin", 112, 120900, 1714.7])
x.add_row(["Hobart", 1357, 205556, 619.5])
x.add_row(["Sydney", 2058, 4336374, 1214.8])
x.add_row(["Melbourne", 1566, 3806092, 646.9])
x.add_row(["Perth", 5386, 1554769, 869.4])

print(x)

then the argument works:

+-----------+------+------------+-----------------+
| City name | Area | Population | Annual Rainfall |
+-----------+------+------------+-----------------+
|  Adelaide | 1295 |  1158259   |      600.5      |
|  Brisbane | 5905 | 1857594111 |      1146.4     |
|           |      | 1111111111 |                 |
|           |      |  1111111   |                 |
|   Darwin  | 112  |   120900   |      1714.7     |
|   Hobart  | 1357 |   205556   |      619.5      |
|   Sydney  | 2058 |  4336374   |      1214.8     |
| Melbourne | 1566 |  3806092   |      646.9      |
|   Perth   | 5386 |  1554769   |      869.4      |
+-----------+------+------------+-----------------+



@rconvent rconvent assigned rconvent and unassigned rconvent Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants