Skip to content

Commit 18fd253

Browse files
committed
Define table titles and captions as constants and set when creating the tables
1 parent 24d8d83 commit 18fd253

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

examples/rich_tables.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
["🇮🇳", "Mumbai", "India", 22_089_000],
2727
["🇯🇵", "Osaka (大阪)", "Japan", 18_921_600],
2828
]
29+
CITY_TITLE = "10 Largest Cities by Population 2025"
30+
CITY_CAPTION = "Data from https://worldpopulationreview.com/"
2931

3032
COUNTRY_HEADERS = [
3133
'Flag',
@@ -48,6 +50,8 @@
4850
["🇷🇺", "Russia (россия)", 143_997_000, 17.1, 9, 2_076_396, 14_258],
4951
["🇪🇹", "Ethiopia (እትዮጵያ)", 135_472_000, 1.1, 120, 117_457, 1_066],
5052
]
53+
COUNTRY_TITLE = "10 Largest Countries by Population 2025"
54+
COUNTRY_CAPTION = "Data from https://worldpopulationreview.com/ and Wikipedia"
5155

5256

5357
class TableApp(cmd2.Cmd):
@@ -68,9 +72,7 @@ def __init__(self) -> None:
6872
@cmd2.with_category(TABLE_CATEGORY)
6973
def do_cities(self, _: cmd2.Statement) -> None:
7074
"""Display the cities with the largest population."""
71-
table = Table()
72-
table.title = "10 Largest Cities by Population 2025"
73-
table.caption = "Data from https://worldpopulationreview.com/"
75+
table = Table(title=CITY_TITLE, caption=CITY_CAPTION)
7476

7577
for header in CITY_HEADERS:
7678
table.add_column(header)
@@ -85,9 +87,7 @@ def do_cities(self, _: cmd2.Statement) -> None:
8587
@cmd2.with_category(TABLE_CATEGORY)
8688
def do_countries(self, _: cmd2.Statement) -> None:
8789
"""Display the countries with the largest population."""
88-
table = Table()
89-
table.title = "10 Largest Countries by Population 2025"
90-
table.caption = "Data from https://worldpopulationreview.com/ and Wikipedia"
90+
table = Table(title=COUNTRY_TITLE, caption=COUNTRY_CAPTION)
9191

9292
for header in COUNTRY_HEADERS:
9393
justify = "right"

0 commit comments

Comments
 (0)