本文整理汇总了Python中terminaltables.AsciiTable.justify_columns[0]方法的典型用法代码示例。如果您正苦于以下问题:Python AsciiTable.justify_columns[0]方法的具体用法?Python AsciiTable.justify_columns[0]怎么用?Python AsciiTable.justify_columns[0]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类terminaltables.AsciiTable
的用法示例。
在下文中一共展示了AsciiTable.justify_columns[0]方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: search
# 需要导入模块: from terminaltables import AsciiTable [as 别名]
# 或者: from terminaltables.AsciiTable import justify_columns[0] [as 别名]
def search(substring, include_deleted, include_pending, include_external, include_system, **criteria):
"""Searches users matching some criteria"""
assert set(criteria.viewkeys()) == {'first_name', 'last_name', 'email', 'affiliation'}
criteria = {k: v for k, v in criteria.viewitems() if v is not None}
res = search_users(exact=(not substring), include_deleted=include_deleted, include_pending=include_pending,
external=include_external, allow_system_user=include_system, **criteria)
if not res:
print(cformat('%{yellow}No results found'))
return
elif len(res) > 100:
click.confirm('{} results found. Show them anyway?'.format(len(res)), abort=True)
users = sorted((u for u in res if isinstance(u, User)), key=lambda x: (x.first_name.lower(), x.last_name.lower(),
x.email))
externals = sorted((ii for ii in res if isinstance(ii, IdentityInfo)),
key=lambda x: (_safe_lower(x.data.get('first_name')), _safe_lower(x.data.get('last_name')),
_safe_lower(x.data['email'])))
if users:
table_data = [['ID', 'First Name', 'Last Name', 'Email', 'Affiliation']]
for user in users:
table_data.append([unicode(user.id), user.first_name, user.last_name, user.email, user.affiliation])
table = AsciiTable(table_data, cformat('%{white!}Users%{reset}'))
table.justify_columns[0] = 'right'
print(table.table)
if externals:
if users:
print()
table_data = [['First Name', 'Last Name', 'Email', 'Affiliation', 'Source', 'Identifier']]
for ii in externals:
data = ii.data
table_data.append([data.get('first_name', ''), data.get('last_name', ''), data['email'],
data.get('affiliation', '-'), ii.provider.name, ii.identifier])
table = AsciiTable(table_data, cformat('%{white!}Externals%{reset}'))
print(table.table)
示例2: print_pokemon
# 需要导入模块: from terminaltables import AsciiTable [as 别名]
# 或者: from terminaltables.AsciiTable import justify_columns[0] [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: test_single_line
# 需要导入模块: from terminaltables import AsciiTable [as 别名]
# 或者: from terminaltables.AsciiTable import justify_columns[0] [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
示例4: __report_percentiles
# 需要导入模块: from terminaltables import AsciiTable [as 别名]
# 或者: from terminaltables.AsciiTable import justify_columns[0] [as 别名]
def __report_percentiles(self, summary_kpi_set):
"""
reports percentiles
"""
fmt = "Average times: total %.3f, latency %.3f, connect %.3f"
self.log.info(fmt, summary_kpi_set[KPISet.AVG_RESP_TIME], summary_kpi_set[KPISet.AVG_LATENCY],
summary_kpi_set[KPISet.AVG_CONN_TIME])
data = [("Percentile, %", "Resp. Time, s")]
for key in sorted(summary_kpi_set[KPISet.PERCENTILES].keys(), key=float):
data.append((float(key), summary_kpi_set[KPISet.PERCENTILES][key]))
# self.log.info("Percentile %.1f%%: %.3f", )
table = SingleTable(data) if sys.stdout.isatty() else AsciiTable(data)
table.justify_columns[0] = 'right'
table.justify_columns[1] = 'right'
self.log.info("Percentiles:\n%s", table.table)
示例5: run_model
# 需要导入模块: from terminaltables import AsciiTable [as 别名]
# 或者: from terminaltables.AsciiTable import justify_columns[0] [as 别名]
#.........这里部分代码省略.........
for key, value in G.pmlthickness.items():
pmlinfo += '{}: {}, '.format(key, value)
pmlinfo = pmlinfo[:-2]
print('PML boundaries: {} cells'.format(pmlinfo))
pbar = tqdm(total=sum(1 for value in G.pmlthickness.values() if value > 0), desc='Building PML boundaries', ncols=get_terminal_width() - 1, file=sys.stdout, disable=G.tqdmdisable)
build_pmls(G, pbar)
pbar.close()
# Build the model, i.e. set the material properties (ID) for every edge of every Yee cell
print()
pbar = tqdm(total=2, desc='Building main grid', ncols=get_terminal_width() - 1, file=sys.stdout, disable=G.tqdmdisable)
build_electric_components(G.solid, G.rigidE, G.ID, G)
pbar.update()
build_magnetic_components(G.solid, G.rigidH, G.ID, G)
pbar.update()
pbar.close()
# Process any voltage sources (that have resistance) to create a new material at the source location
for voltagesource in G.voltagesources:
voltagesource.create_material(G)
# Initialise arrays of update coefficients to pass to update functions
G.initialise_std_update_coeff_arrays()
# Initialise arrays of update coefficients and temporary values if there are any dispersive materials
if Material.maxpoles != 0:
G.initialise_dispersive_arrays()
# Process complete list of materials - calculate update coefficients, store in arrays, and build text list of materials/properties
materialsdata = process_materials(G)
if G.messages:
materialstable = AsciiTable(materialsdata)
materialstable.outer_border = False
materialstable.justify_columns[0] = 'right'
print(materialstable.table)
# Check to see if numerical dispersion might be a problem
results = dispersion_analysis(G)
if results['deltavp'] and np.abs(results['deltavp']) > G.maxnumericaldisp:
print(Fore.RED + "\nWARNING: Potentially significant numerical dispersion. Largest physical phase-velocity error is {:.2f}% in material '{}' with wavelength sampled by {} cells (maximum significant frequency {:g}Hz)".format(results['deltavp'], results['material'].ID, round_value(results['N']), results['maxfreq']) + Style.RESET_ALL)
elif results['deltavp']:
print("\nNumerical dispersion analysis: largest physical phase-velocity error is {:.2f}% in material '{}' with wavelength sampled by {} cells (maximum significant frequency {:g}Hz)".format(results['deltavp'], results['material'].ID, round_value(results['N']), results['maxfreq']))
# If geometry information to be reused between model runs
else:
inputfilestr = '\n--- Model {} of {}, input file (not re-processed, i.e. geometry fixed): {}'.format(modelrun, numbermodelruns, inputfile)
print(Fore.GREEN + '{} {}\n'.format(inputfilestr, '-' * (get_terminal_width() - 1 - len(inputfilestr))) + Style.RESET_ALL)
# Clear arrays for field components
G.initialise_field_arrays()
# Clear arrays for fields in PML
for pml in G.pmls:
pml.initialise_field_arrays()
# Adjust position of simple sources and receivers if required
if G.srcsteps[0] > 0 or G.srcsteps[1] > 0 or G.srcsteps[2] > 0:
for source in itertools.chain(G.hertziandipoles, G.magneticdipoles):
if modelrun == 1:
if source.xcoord + G.srcsteps[0] * (numbermodelruns - 1) > G.nx or source.ycoord + G.srcsteps[1] * (numbermodelruns - 1) > G.ny or source.zcoord + G.srcsteps[2] * (numbermodelruns - 1) > G.nz:
raise GeneralError('Source(s) will be stepped to a position outside the domain.')
source.xcoord = source.xcoordorigin + (modelrun - 1) * G.srcsteps[0]
source.ycoord = source.ycoordorigin + (modelrun - 1) * G.srcsteps[1]
source.zcoord = source.zcoordorigin + (modelrun - 1) * G.srcsteps[2]
if G.rxsteps[0] > 0 or G.rxsteps[1] > 0 or G.rxsteps[2] > 0:
for receiver in G.rxs:
示例6: test_attributes
# 需要导入模块: from terminaltables import AsciiTable [as 别名]
# 或者: from terminaltables.AsciiTable import justify_columns[0] [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 | |
+------------+-------+-----------+""")
#.........这里部分代码省略.........