本文整理汇总了Python中terminaltables.AsciiTable.justify_columns[2]方法的典型用法代码示例。如果您正苦于以下问题:Python AsciiTable.justify_columns[2]方法的具体用法?Python AsciiTable.justify_columns[2]怎么用?Python AsciiTable.justify_columns[2]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类terminaltables.AsciiTable
的用法示例。
在下文中一共展示了AsciiTable.justify_columns[2]方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_single_line
# 需要导入模块: from terminaltables import AsciiTable [as 别名]
# 或者: from terminaltables.AsciiTable import justify_columns[2] [as 别名]
def test_single_line():
"""Test single-lined cells."""
table_data = [
['Name', 'Color', 'Type'],
['Avocado', 'green', 'nut'],
['Tomato', 'red', 'fruit'],
['Lettuce', 'green', 'vegetable'],
['Watermelon', 'green'],
[],
]
table = AsciiTable(table_data, 'Example')
table.inner_footing_row_border = True
table.justify_columns[0] = 'left'
table.justify_columns[1] = 'center'
table.justify_columns[2] = 'right'
actual = table.table
expected = (
'+Example-----+-------+-----------+\n'
'| Name | Color | Type |\n'
'+------------+-------+-----------+\n'
'| Avocado | green | nut |\n'
'| Tomato | red | fruit |\n'
'| Lettuce | green | vegetable |\n'
'| Watermelon | green | |\n'
'+------------+-------+-----------+\n'
'| | | |\n'
'+------------+-------+-----------+'
)
assert actual == expected
示例2: print_pokemon
# 需要导入模块: from terminaltables import AsciiTable [as 别名]
# 或者: from terminaltables.AsciiTable import justify_columns[2] [as 别名]
def print_pokemon(self):
"""Print Pokemon and their stats"""
sorted_mons = sorted(self.pokemon, key=lambda k: (k['num'], -k['iv_percent']))
groups = groupby(sorted_mons, key=lambda k: k['num'])
table_data = [
['Pokemon', 'CP', 'IV %', 'ATK', 'DEF', 'STA']
]
for key, group in groups:
group = list(group)
pokemon_name = self.pokemon_list[str(key)].replace(u'\N{MALE SIGN}', '(M)').replace(u'\N{FEMALE SIGN}', '(F)')
best_iv_pokemon = max(group, key=lambda k: k['iv_percent'])
best_iv_pokemon['best_iv'] = True
for pokemon in group:
row_data = [
pokemon_name,
pokemon['cp'],
"{0:.0f}%".format(pokemon['iv_percent']),
pokemon['attack'],
pokemon['defense'],
pokemon['stamina']
]
table_data.append(row_data)
table = AsciiTable(table_data)
table.justify_columns[0] = 'left'
table.justify_columns[1] = 'right'
table.justify_columns[2] = 'right'
table.justify_columns[3] = 'right'
table.justify_columns[4] = 'right'
table.justify_columns[5] = 'right'
print(table.table)
示例3: print_table
# 需要导入模块: from terminaltables import AsciiTable [as 别名]
# 或者: from terminaltables.AsciiTable import justify_columns[2] [as 别名]
def print_table(data):
"""Print the table of detected SSIDs and their data to screen.
Positional arguments:
data -- list of dictionaries.
"""
table = AsciiTable([COLUMNS])
table.justify_columns[2] = 'right'
table.justify_columns[3] = 'right'
table.justify_columns[4] = 'right'
table_data = list()
for row_in in data:
row_out = [
str(row_in.get('ssid', '')).replace('\0', ''),
str(row_in.get('security', '')),
str(row_in.get('channel', '')),
str(row_in.get('frequency', '')),
str(row_in.get('signal', '')),
str(row_in.get('bssid', '')),
]
if row_out[3]:
row_out[3] += ' MHz'
if row_out[4]:
row_out[4] += ' dBm'
table_data.append(row_out)
sort_by_column = [c.lower() for c in COLUMNS].index(OPTIONS['--key'].lower())
table_data.sort(key=lambda c: c[sort_by_column], reverse=OPTIONS['--reverse'])
table.table_data.extend(table_data)
print(table.table)
示例4: main
# 需要导入模块: from terminaltables import AsciiTable [as 别名]
# 或者: from terminaltables.AsciiTable import justify_columns[2] [as 别名]
def main():
"""Main function."""
title = 'Jetta SportWagen'
# AsciiTable.
table_instance = AsciiTable(TABLE_DATA, title)
table_instance.justify_columns[2] = 'right'
print(table_instance.table)
print()
# SingleTable.
table_instance = SingleTable(TABLE_DATA, title)
table_instance.justify_columns[2] = 'right'
print(table_instance.table)
print()
# DoubleTable.
table_instance = DoubleTable(TABLE_DATA, title)
table_instance.justify_columns[2] = 'right'
print(table_instance.table)
print()
示例5: get_weather
# 需要导入模块: from terminaltables import AsciiTable [as 别名]
# 或者: from terminaltables.AsciiTable import justify_columns[2] [as 别名]
def get_weather(location):
if location is None:
g = geocoder.ip('me')
else:
g = geocoder.google(location)
url = "https://api.darksky.net/forecast/{}/{},{}?exclude=minutely,hourly,alerts,flags?UNITS={}".format(DARKSKY_API_KEY, g.lat, g.lng, UNITS)
response = requests.get(url).json()
table_week = [["", "", "HI", "at", "LO", "at", "", ""]]
for day in response['daily']['data']:
date = datetime.datetime.fromtimestamp(int(day['time'])).strftime('%a %b %-d')
summary = day['summary']
max_temp = temp_format(colors.RED, day['temperatureMax'])
max_temp_time = readable_time(day['temperatureMaxTime'])
min_temp = temp_format(colors.BLUE, day['temperatureMin'])
min_temp_time = readable_time(day['temperatureMinTime'])
percip_chance = str(int(day['precipProbability'] * 100)) + "%"
try:
percip_type = day['precipType'].title()
except KeyError:
percip_type = ""
table_day = [date, summary, max_temp, max_temp_time, min_temp, min_temp_time, percip_chance, percip_type]
table_week.append(table_day)
table_week[1][0] = colors.BOLD + colors.GREEN + "* Today *" + colors.ENDC
title = colors.BOLD + " {}, {} - Current Temp: {} ".format(g.city, g.state, (str(int(response['currently']['temperature'])) + UNIT_LETTER)) + colors.ENDC
# AsciiTable
table_instance = AsciiTable(table_week, title)
table_instance.justify_columns[2] = 'right'
# Output
print("\n" + colors.BOLD + response['daily']['summary'] + colors.ENDC + "\n")
print(table_instance.table)
示例6: calc_min_delay
# 需要导入模块: from terminaltables import AsciiTable [as 别名]
# 或者: from terminaltables.AsciiTable import justify_columns[2] [as 别名]
damage, hit, base_delay = parts[2:5]
# find weapon sizes
if re.match('.*SIZE_.*SIZE_', line):
# skip long gone items
if 'old ' in title[0:4]:
continue
parts = [x.strip() for x in line.split(',')]
double_hand, single_hand = parts[1:3]
min_delay = calc_min_delay(base_delay)
skill_required = calc_skill_required(base_delay, min_delay)
th = parse_2h_size(double_hand, parse_1h_size(single_hand), parts[0])
table_data.append([title, damage, hit, base_delay, min_delay, skill_required, th])
# table_data = sorted(table_data, key=lambda x: x[0])
table_data.insert(0, header)
table_data.append(header)
table = AsciiTable(table_data)
table.title = table_title
table.inner_footing_row_border = True
table.justify_columns[1] = 'right'
table.justify_columns[2] = 'right'
table.justify_columns[3] = 'right'
table.justify_columns[4] = 'right'
table.justify_columns[5] = 'right'
print(table.table)
print('\r')
print('Last generated on {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now()))
示例7: test_attributes
# 需要导入模块: from terminaltables import AsciiTable [as 别名]
# 或者: from terminaltables.AsciiTable import justify_columns[2] [as 别名]
def test_attributes():
"""Test table attributes."""
table_data = [
['Name', 'Color', 'Type'],
['Avocado', 'green', 'nut'],
['Tomato', 'red', 'fruit'],
['Lettuce', 'green', 'vegetable'],
['Watermelon', 'green']
]
table = AsciiTable(table_data)
table.justify_columns[0] = 'right'
expected = dedent("""\
+------------+-------+-----------+
| Name | Color | Type |
+------------+-------+-----------+
| Avocado | green | nut |
| Tomato | red | fruit |
| Lettuce | green | vegetable |
| Watermelon | green | |
+------------+-------+-----------+""")
assert expected == table.table
table.justify_columns[2] = 'center'
expected = dedent("""\
+------------+-------+-----------+
| Name | Color | Type |
+------------+-------+-----------+
| Avocado | green | nut |
| Tomato | red | fruit |
| Lettuce | green | vegetable |
| Watermelon | green | |
+------------+-------+-----------+""")
assert expected == table.table
table.inner_heading_row_border = False
expected = dedent("""\
+------------+-------+-----------+
| Name | Color | Type |
| Avocado | green | nut |
| Tomato | red | fruit |
| Lettuce | green | vegetable |
| Watermelon | green | |
+------------+-------+-----------+""")
assert expected == table.table
table.title = 'Foods'
table.inner_column_border = False
expected = dedent("""\
+Foods-------------------------+
| Name Color Type |
| Avocado green nut |
| Tomato red fruit |
| Lettuce green vegetable |
| Watermelon green |
+------------------------------+""")
assert expected == table.table
table.outer_border = False
expected = (
' Name Color Type \n'
' Avocado green nut \n'
' Tomato red fruit \n'
' Lettuce green vegetable \n'
' Watermelon green '
)
assert expected == table.table
table.outer_border = True
table.inner_row_border = True
expected = dedent("""\
+Foods-------------------------+
| Name Color Type |
+------------------------------+
| Avocado green nut |
+------------------------------+
| Tomato red fruit |
+------------------------------+
| Lettuce green vegetable |
+------------------------------+
| Watermelon green |
+------------------------------+""")
assert expected == table.table
table.title = False
table.inner_column_border = True
table.inner_heading_row_border = False # Ignored due to inner_row_border.
table.inner_row_border = True
expected = dedent("""\
+------------+-------+-----------+
| Name | Color | Type |
+------------+-------+-----------+
| Avocado | green | nut |
+------------+-------+-----------+
| Tomato | red | fruit |
+------------+-------+-----------+
| Lettuce | green | vegetable |
+------------+-------+-----------+
| Watermelon | green | |
+------------+-------+-----------+""")
#.........这里部分代码省略.........