本文整理汇总了Python中texttable.Texttable.set_cols_valign方法的典型用法代码示例。如果您正苦于以下问题:Python Texttable.set_cols_valign方法的具体用法?Python Texttable.set_cols_valign怎么用?Python Texttable.set_cols_valign使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类texttable.Texttable
的用法示例。
在下文中一共展示了Texttable.set_cols_valign方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_colored
# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_cols_valign [as 别名]
def test_colored():
table = Texttable()
table.set_cols_align(["l", "r", "c"])
table.set_cols_valign(["t", "m", "b"])
table.add_rows([
[get_color_string(bcolors.GREEN, "Name Of Person"), "Age", "Nickname"],
["Mr\nXavier\nHuon", 32, "Xav'"],
[get_color_string(bcolors.BLUE,"Mr\nBaptiste\nClement"),
1,
get_color_string(bcolors.RED,"Baby")] ])
expected_output = dedent("""
+----------------+-----+----------+
| [92mName Of Person[0m | Age | Nickname |
+================+=====+==========+
| Mr | | |
| Xavier | 32 | |
| Huon | | Xav' |
+----------------+-----+----------+
| [94mMr[0m | | |
| [94mBaptiste[0m | 1 | |
| [94mClement[0m | | [91mBaby[0m |
+----------------+-----+----------+
""").strip('\n')
assert table.draw() == expected_output
示例2: render_instruments_as_table
# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_cols_valign [as 别名]
def render_instruments_as_table(instruments, display_heading=True):
"""
Returns ASCII table view of instruments.
:param instruments: The instruments to be rendered.
:type instruments: :class:`mytardisclient.models.resultset.ResultSet`
:param render_format: The format to display the data in ('table' or
'json').
:param display_heading: Setting `display_heading` to True ensures
that the meta information returned by the query is summarized
in a 'heading' before displaying the table. This meta
information can be used to determine whether the query results
have been truncated due to pagination.
"""
heading = "\n" \
"Model: Instrument\n" \
"Query: %s\n" \
"Total Count: %s\n" \
"Limit: %s\n" \
"Offset: %s\n\n" \
% (instruments.url, instruments.total_count,
instruments.limit, instruments.offset) if display_heading else ""
table = Texttable(max_width=0)
table.set_cols_align(["r", 'l', 'l'])
table.set_cols_valign(['m', 'm', 'm'])
table.header(["ID", "Name", "Facility"])
for instrument in instruments:
table.add_row([instrument.id, instrument.name, instrument.facility])
return heading + table.draw() + "\n"
示例3: render_datasets_as_table
# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_cols_valign [as 别名]
def render_datasets_as_table(datasets, display_heading=True):
"""
Returns ASCII table view of datasets.
:param datasets: The datasets to be rendered.
:type datasets: :class:`mytardisclient.models.resultset.ResultSet`
:param render_format: The format to display the data in ('table' or
'json').
:param display_heading: Setting `display_heading` to True ensures
that the meta information returned by the query is summarized
in a 'heading' before displaying the table. This meta
information can be used to determine whether the query results
have been truncated due to pagination.
"""
heading = "\n" \
"Model: Dataset\n" \
"Query: %s\n" \
"Total Count: %s\n" \
"Limit: %s\n" \
"Offset: %s\n\n" \
% (datasets.url, datasets.total_count,
datasets.limit, datasets.offset) if display_heading else ""
table = Texttable(max_width=0)
table.set_cols_align(["r", 'l', 'l', 'l'])
table.set_cols_valign(['m', 'm', 'm', 'm'])
table.header(["Dataset ID", "Experiment(s)", "Description", "Instrument"])
for dataset in datasets:
table.add_row([dataset.id, "\n".join(dataset.experiments),
dataset.description, dataset.instrument])
return heading + table.draw() + "\n"
示例4: view
# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_cols_valign [as 别名]
def view(self, key=None):
"""Nice stack data view.
Use colorama module to highlight key if passed and
texttable for data visualisation
"""
def __print_select():
for idx, row in enumerate(self):
for i in row:
if key in i:
console_logger.info("select('%s').key(%s)\n" %
(Fore.RED + row['class'] + Style.RESET_ALL,
Fore.RED + i + Style.RESET_ALL))
console_logger.info("Value of '%s' is %s\n" % (i,
Fore.RED + str(row[i]) + Style.RESET_ALL))
console_logger.info("\nStack size: %s\n" % self.size())
table = Texttable()
table.set_cols_align(["c", "c"])
table.set_cols_valign(["t", "m"])
table.set_cols_width([8, 150])
table.add_row(["Current Index", "Entry"])
for idx, row in enumerate(self):
table.add_row([idx, row])
console_logger.info(table.draw() + "\n")
if key:
__print_select()
示例5: test_texttable
# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_cols_valign [as 别名]
def test_texttable():
table = Texttable()
table.set_cols_align(["l", "r", "c"])
table.set_cols_valign(["t", "m", "b"])
table.add_rows([
["Name", "Age", "Nickname"],
["Mr\nXavier\nHuon", 32, "Xav'"],
["Mr\nBaptiste\nClement", 1, "Baby"],
["Mme\nLouise\nBourgeau", 28, "Lou\n \nLoue"],
])
assert clean(table.draw()) == dedent('''\
+----------+-----+----------+
| Name | Age | Nickname |
+==========+=====+==========+
| Mr | | |
| Xavier | 32 | |
| Huon | | Xav' |
+----------+-----+----------+
| Mr | | |
| Baptiste | 1 | |
| Clement | | Baby |
+----------+-----+----------+
| Mme | | Lou |
| Louise | 28 | |
| Bourgeau | | Loue |
+----------+-----+----------+
''')
示例6: print_steps
# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_cols_valign [as 别名]
def print_steps(self, show_result=True):
def max_len_of_list_of_str(s):
return max(len(line) for line in str(s).split('\n'))
def autodetect_width(d):
widths = [0] * len(d[0])
for line in d:
for _i in range(len(line)):
widths[_i] = max(widths[_i], max_len_of_list_of_str(line[_i]))
return widths
if self.save_history:
if self.errors:
self.history = self.history[:-1]
t = Texttable()
header = ['№', 'Term', 'Code'] if self.parallel else ['№', 'Term', 'Code', 'Stack']
data = [header] + [
[repr(i) for i in item][:-1] if self.parallel else [repr(i) for i in item] for item in self.history]
t.add_rows(data)
t.set_cols_align(['l'] + ['r'] * (len(header) - 1))
t.set_cols_valign(['m'] + ['m'] * (len(header) - 1))
t.set_cols_width(autodetect_width(data))
print t.draw()
else:
if not self.errors:
print ' Steps: %10s' % self.iteration
if show_result:
print 'Result: %10s' % repr(self.term)
示例7: render_schemas_as_table
# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_cols_valign [as 别名]
def render_schemas_as_table(schemas, display_heading=True):
"""
Returns ASCII table view of schemas.
:param schemas: The schemas to be rendered.
:type schemas: :class:`mytardisclient.models.resultset.ResultSet`
:param render_format: The format to display the data in ('table' or
'json').
:param display_heading: Setting `display_heading` to True ensures
that the meta information returned by the query is summarized
in a 'heading' before displaying the table. This meta
information can be used to determine whether the query results
have been truncated due to pagination.
"""
heading = "\n" \
"Model: Schema\n" \
"Query: %s\n" \
"Total Count: %s\n" \
"Limit: %s\n" \
"Offset: %s\n\n" \
% (schemas.url, schemas.total_count,
schemas.limit, schemas.offset) if display_heading else ""
table = Texttable(max_width=0)
table.set_cols_align(["r", 'l', 'l', 'l', 'l', 'l', 'l'])
table.set_cols_valign(['m', 'm', 'm', 'm', 'm', 'm', 'm'])
table.header(["ID", "Name", "Namespace", "Type", "Subtype", "Immutable",
"Hidden"])
for schema in schemas:
table.add_row([schema.id, schema.name, schema.namespace,
schema.type, schema.subtype or '',
str(bool(schema.immutable)), str(bool(schema.hidden))])
return heading + table.draw() + "\n"
示例8: check
# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_cols_valign [as 别名]
def check(f, f_grad, x0, name, verbose=False):
"""
Checks whether gradients of function ``f`` at point x0 is same as the gradients provided by ``f_grad``.
``error`` is the difference between numerical and provided gradients.
'%error' = abs(error) / numerical gradient.
Parameters
----------
f : callable
input function to check gradients against
f_grad : callable
input function which provides gradients
x0 : ndarray
the point at which gradients should be calculated
name : list
a vector with the size of the number of parameters, which provides name for each parameter. This
name will be used when generating output table
verbose : boolean
whether to print output for each parameter separately
Returns
-------
avg : float
average of the percentage error over all the parameters, i.e., mean(%error)
"""
g = f_grad(x0)
if len(g) != len(x0):
raise Exception('dimensions mismatch')
table = Texttable()
table.set_cols_align(["l", "r", "c", "c", "c"])
table.set_cols_valign(["t", "m", "b" , "r", "c"])
rows = []
rows += [["Name ", "analytical ", "numerical ", "error ", "% error "]]
if verbose:
print 'dimensions:', len(x0)
aver_error = 0
for i in range(len(x0)):
def f_i(x):
return f((concatenate((x0[:i], x, x0[(i+1):]))))
t = get_d1(f_i, [x0[i]])
p_errro=None
if t != 0:
p_errro = abs(t-g[i]) / abs(t)
rows += [[name[i], g[i], t, abs(t-g[i]), p_errro]]
if abs(g[i]) <1e-4 and abs(t) < 1e-4:
pass
else:
aver_error += abs(t-g[i]) / abs(t)
if verbose:
print 'element:', i
table.add_rows(rows)
if verbose:
print(table.draw())
return aver_error / len(x0)
示例9: main
# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_cols_valign [as 别名]
def main():
getInodes(".")
table = Texttable()
table.set_cols_align(["l", "c", "c"])
table.set_cols_valign(["t", "m", "m"])
rows = [["File Names", "Inode", "Links Amount"]]
rows.extend([ ("\n".join(inodes[inode] + symlinks[inode]), inode, len(inodes[inode])) for inode in inodes.viewkeys() | symlinks.viewkeys()])
table.add_rows(rows)
print (table.draw())
示例10: list_apps
# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_cols_valign [as 别名]
def list_apps(apps):
"""Print applications into a pretty table.
"""
table = Texttable()
table.set_cols_align(["r", "l", "l"])
table.set_cols_valign(["m", "m", "m"])
table.add_rows([ ['App #', 'App name', 'App ID #'], ], header = True)
c=0
for webapp in apps:
c+=1
table.add_row([c, webapp['name'], webapp['id']])
# Print table.
print (table.draw() + '\n')
return True
示例11: connectionsTable
# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_cols_valign [as 别名]
def connectionsTable(connections, output_format):
"""
Get connections in the given output format.
"""
table = Texttable(max_width=0)
# Alignments
table.set_cols_valign(["m", "t", "t", "t", "t", "t", "m", "t", "t"])
table.set_cols_align(["l", "l", "c", "l", "l", "c", "c", "l", "l"])
# Header
table.add_row(["#", "Station", "Platform", "Date", "Time", "Duration", "Chg.", "With", "Occupancy"])
# Connection rows
for i, c in enumerate(connections):
table.add_row(_getConnectionRow(i, c))
# Display
return table.draw()
示例12: autodoc_class
# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_cols_valign [as 别名]
def autodoc_class(cls, model_cls):
res = [":Declaration type: Mixin"]
res.extend([':Inherit model or mixin:', ''])
res.extend([' * ' + str(x) for x in model_cls.__anyblok_bases__])
res.extend(['', ''])
if has_sql_fields([model_cls]):
rows = [['field name', 'Description']]
rows.extend([x, y.autodoc()]
for x, y in get_fields(model_cls).items())
table = Texttable()
table.set_cols_valign(["m", "t"])
table.add_rows(rows)
res.extend([table.draw(), '', ''])
return '\n'.join(res)
示例13: render_instrument_as_table
# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_cols_valign [as 别名]
def render_instrument_as_table(instrument):
"""
Returns ASCII table view of instrument.
:param instrument: The instrument to be rendered.
:type instrument: :class:`mytardisclient.models.instrument.Instrument`
"""
instrument_table = Texttable()
instrument_table.set_cols_align(['l', 'l'])
instrument_table.set_cols_valign(['m', 'm'])
instrument_table.header(["Instrument field", "Value"])
instrument_table.add_row(["ID", instrument.id])
instrument_table.add_row(["Name", instrument.name])
instrument_table.add_row(["Facility", instrument.facility])
return instrument_table.draw() + "\n"
示例14: print_table
# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_cols_valign [as 别名]
def print_table(difftable, name1, name2, detailed=False):
table = Texttable(max_width=0)
table.set_cols_align(["l", "l", "l", "l", "l"])
table.set_cols_valign(["m", "m", "m", "m", "m"])
table.add_row(["Counter Group", "Counter Name", name1, name2, "delta"]);
for k in sorted(difftable):
# ignore task specific counters in default output
if not detailed and ("_INPUT_" in k or "_OUTPUT_" in k):
continue
v = difftable[k]
row = []
# counter group. using shortname here instead of FQCN
if detailed:
row.append(k)
else:
row.append(k.split(".")[-1])
# keys as list (counter names)
row.append("\n".join(list(v.keys())))
# counter values for dag1
for key, value in v.items():
if len(value) == 1:
value.append(0)
value.append(value[0] - value[1])
# dag1 counter values
name1Val = []
for key, value in v.items():
name1Val.append(str(value[0]))
row.append("\n".join(name1Val))
# dag2 counter values
name2Val = []
for key, value in v.items():
name2Val.append(str(value[1]))
row.append("\n".join(name2Val))
# delta values
deltaVal = []
for key, value in v.items():
deltaVal.append(str(value[2]))
row.append("\n".join(deltaVal))
table.add_row(row)
print table.draw() + "\n"
示例15: autodoc_fields
# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_cols_valign [as 别名]
def autodoc_fields(declaration_cls, model_cls):
"""Produces autodocumentation table for the fields.
Exposed as a function in order to be reusable by a simple export,
e.g., from anyblok.mixin.
"""
if not has_sql_fields([model_cls]):
return ''
rows = [['Fields', '']]
rows.extend([x, y.autodoc()]
for x, y in get_fields(model_cls).items())
table = Texttable(max_width=0)
table.set_cols_valign(["m", "t"])
table.add_rows(rows)
return table.draw() + '\n\n'