Skip to content

Commit 83f74c7

Browse files
committed
Added city names in their native tongue in parentheses to demonstrate unicode capability
- Mandarin, Urdu, and Turkish all seem to be working fine - But something is up with Hindi - the table/colum width calculation is messed up for Mumbai
1 parent ac370cb commit 83f74c7

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

examples/table_display.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,13 @@ def two_dec(num: float) -> str:
5252

5353

5454
# ############ Table data formatted as an iterable of iterable fields ############
55-
56-
EXAMPLE_ITERABLE_DATA = [['Shanghai', 'Shanghai', 'China', 'Asia', 24183300, 6340.5],
57-
['Beijing', 'Hebei', 'China', 'Asia', 20794000, 1749.57],
58-
['Karachi', 'Sindh', 'Pakistan', 'Asia', 14910352, 615.58],
59-
['Shenzen', 'Guangdong', 'China', 'Asia', 13723000, 1493.32],
60-
['Guangzho', 'Guangdong', 'China', 'Asia', 13081000, 1347.81],
61-
['Mumbai', 'Maharashtra', 'India', 'Asia', 12442373, 465.78],
62-
['Istanbul', 'Istanbul', 'Turkey', 'Eurasia', 12661000, 620.29],
55+
EXAMPLE_ITERABLE_DATA = [['Shanghai (上海)', 'Shanghai', 'China', 'Asia', 24183300, 6340.5],
56+
['Beijing (北京市)', 'Hebei', 'China', 'Asia', 20794000, 1749.57],
57+
['Karachi (کراچی)', 'Sindh', 'Pakistan', 'Asia', 14910352, 615.58],
58+
['Shenzen (深圳市)', 'Guangdong', 'China', 'Asia', 13723000, 1493.32],
59+
['Guangzho (广州市)', 'Guangdong', 'China', 'Asia', 13081000, 1347.81],
60+
['Mumbai (बॉम्बे हिंदी)', 'Maharashtra', 'India', 'Asia', 12442373, 465.78],
61+
['Istanbul (İstanbuld)', 'Istanbul', 'Turkey', 'Eurasia', 12661000, 620.29],
6362
]
6463

6564
# Calculate population density
@@ -68,7 +67,7 @@ def two_dec(num: float) -> str:
6867

6968

7069
# # Column headers plus optional formatting info for each column
71-
columns = [tf.Column('City', header_halign=tf.ColumnAlignment.AlignCenter),
70+
columns = [tf.Column('City', width=11, header_halign=tf.ColumnAlignment.AlignCenter),
7271
tf.Column('Province', header_halign=tf.ColumnAlignment.AlignCenter),
7372
'Country', # NOTE: If you don't need any special effects, you can just pass a string
7473
tf.Column('Continent', cell_halign=tf.ColumnAlignment.AlignCenter),
@@ -109,14 +108,10 @@ def pop_density(data: CityInfo):
109108
return ''
110109

111110

112-
EXAMPLE_OBJECT_DATA = [CityInfo('Shanghai', 'Shanghai', 'China', 'Asia', 24183300, 6340.5),
113-
CityInfo('Beijing', 'Hebei', 'China', 'Asia', 20794000, 1749.57),
114-
CityInfo('Karachi', 'Sindh', 'Pakistan', 'Asia', 14910352, 615.58),
115-
CityInfo('Shenzen', 'Guangdong', 'China', 'Asia', 13723000, 1493.32),
116-
CityInfo('Guangzho', 'Guangdong', 'China', 'Asia', 13081000, 1347.81),
117-
CityInfo('Mumbai', 'Maharashtra', 'India', 'Asia', 12442373, 465.78),
118-
CityInfo('Istanbul', 'Istanbul', 'Turkey', 'Eurasia', 12661000, 620.29),
119-
]
111+
# Convert the Iterable of Iterables data to an Iterable of non-iterable objects for demonstration purposes
112+
EXAMPLE_OBJECT_DATA = []
113+
for city in EXAMPLE_ITERABLE_DATA:
114+
EXAMPLE_OBJECT_DATA.append(CityInfo(city[0], city[1], city[2], city[3], city[4], city[5]))
120115

121116
# If table entries are python objects, all columns must be defined with the object attribute to query for each field
122117
# - attributes can be fields or functions. If a function is provided, the formatter will automatically call

0 commit comments

Comments
 (0)