本文整理汇总了Python中prettytable.PLAIN_COLUMNS属性的典型用法代码示例。如果您正苦于以下问题:Python prettytable.PLAIN_COLUMNS属性的具体用法?Python prettytable.PLAIN_COLUMNS怎么用?Python prettytable.PLAIN_COLUMNS使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类prettytable
的用法示例。
在下文中一共展示了prettytable.PLAIN_COLUMNS属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _make_table
# 需要导入模块: import prettytable [as 别名]
# 或者: from prettytable import PLAIN_COLUMNS [as 别名]
def _make_table(columns, header=False, align=None):
"""Make a table object for output."""
if not align:
align = {}
table = prettytable.PrettyTable(columns)
for col in columns:
table.align[col] = align.get(col, 'l')
table.set_style(prettytable.PLAIN_COLUMNS)
# For some reason, headers must be disable after set_style.
table.header = header
table.left_padding_width = 0
table.right_padding_width = 2
return table
示例2: plain_column_table
# 需要导入模块: import prettytable [as 别名]
# 或者: from prettytable import PLAIN_COLUMNS [as 别名]
def plain_column_table(header, align='l'):
table = PrettyTable(header)
table.set_style(PLAIN_COLUMNS)
table.align = align
return table
示例3: printLevel2
# 需要导入模块: import prettytable [as 别名]
# 或者: from prettytable import PLAIN_COLUMNS [as 别名]
def printLevel2(respjson, outformat, mainkey, listkey, subkey=None):
if mainkey:
parsed = json.loads(respjson)
p=defaultprettytable(listkey)
if(outformat.startswith("json")) :
print(json.dumps(parsed, indent=4, sort_keys=True))
else:
if(outformat.startswith("text")):
p.set_style(prettytable.PLAIN_COLUMNS)
mainId = respjson
if mainkey and len(mainkey) > 0:
mainId = parsed[mainkey]
for n in range(len(mainId)):
item = mainId[n]
#for item in mainId:
if not (subkey is None):
item = item[subkey]
vals = list()
for colkey in listkey:
if colkey in item:
vals.append(item[colkey])
else:
vals.append(" ")
p.add_row(vals)
print(p.get_string())
示例4: printJsonTableTransverse
# 需要导入模块: import prettytable [as 别名]
# 或者: from prettytable import PLAIN_COLUMNS [as 别名]
def printJsonTableTransverse(jsonval, outformat, mainkey):
parsed = json.loads(jsonval)
if(outformat.startswith("json")):
print(json.dumps(parsed, indent=4, sort_keys=True))
else:
if(outformat.startswith("text")):
x.set_style(prettytable.PLAIN_COLUMNS)
if mainkey:
id_generator(parsed[mainkey], "")
else:
id_generator(parsed, "")
print(x.get_string())
示例5: do_list
# 需要导入模块: import prettytable [as 别名]
# 或者: from prettytable import PLAIN_COLUMNS [as 别名]
def do_list(self, args):
"""Lists registered agents"""
t = PrettyTable(['ID', 'Hostname', 'User', 'IP Address', 'Version'])
t.set_style(PLAIN_COLUMNS)
conn = sqlite3.connect('slackor.db')
cursor = conn.execute("SELECT id, hostname, user, ip, version from AGENTS")
for row in cursor:
ID = row[0]
hostname = row[1]
user = row[2]
ipaddr = row[3]
version = row[4]
t.add_row([ID, hostname, user, ipaddr, version])
print(color(t, "blue"))
conn.close()
示例6: show_cards
# 需要导入模块: import prettytable [as 别名]
# 或者: from prettytable import PLAIN_COLUMNS [as 别名]
def show_cards(self, cards, tsv=False, sort='activity', table_fields=[]):
'''Display an iterable of cards all at once.
Uses a pretty-printed table by default, but can also print tab-separated values (TSV).
Supports the following cli commands:
show cards
grep
:param list(trello.Card)|iterable(trello.Card) cards: cards to show
:param bool tsv: display these cards using a tab-separated value format
:param str sort: the field name to sort by (must be a valid field name in this table)
:param list table_fields: display only these fields
'''
# TODO construct the table dynamically instead of filtering down an already-constructed table
# TODO implement a custom sorting functions so the table can be sorted by multiple columns
table = prettytable.PrettyTable()
table.field_names = self.fields.keys()
table.align = 'l'
if tsv:
table.set_style(prettytable.PLAIN_COLUMNS)
else:
table.hrules = prettytable.FRAME
with click.progressbar(list(cards), label='Fetching cards', width=0) as pg:
for card in pg:
table.add_row([x(card) for x in self.fields.values()])
try:
table[0]
except IndexError:
click.secho('No cards match!', fg='red')
raise GTDException(1)
if table_fields:
print(table.get_string(fields=table_fields, sortby=sort))
else:
print(self.resize_and_get_table(table, self.fields.keys(), sort))
示例7: show_boards
# 需要导入模块: import prettytable [as 别名]
# 或者: from prettytable import PLAIN_COLUMNS [as 别名]
def show_boards(ctx, use_json, tsv, by, show_all):
'''Show all boards your account can access'''
if show_all:
boards = ctx.connection.trello.fetch_json('/members/me/boards/?filter=all')
else:
boards = ctx.connection.boards
if use_json:
print(json.dumps(boards, sort_keys=True, indent=2))
return
else:
ctx.display.banner()
# Set up a table to hold our boards
board_columns = ['name', 'activity', 'members', 'permission', 'url']
if by not in board_columns:
click.secho(f'Field {by} is not a valid field: {",".join(board_columns)}', fg='red')
raise GTDException(1)
table = prettytable.PrettyTable()
table.field_names = board_columns
table.align = 'l'
if tsv:
table.set_style(prettytable.PLAIN_COLUMNS)
else:
table.hrules = prettytable.FRAME
for b in boards:
table.add_row(
[
b['name'],
b['dateLastActivity'] or '',
len(b['memberships']),
b['prefs']['permissionLevel'],
b['shortUrl'],
]
)
try:
table[0]
except IndexError:
click.secho('You have no boards!', fg='red')
print(table.get_string(sortby=by))
示例8: list_migrations
# 需要导入模块: import prettytable [as 别名]
# 或者: from prettytable import PLAIN_COLUMNS [as 别名]
def list_migrations():
db_conf = db_context()
db_preflight(db_conf['params'], db_conf['retries'])
with session_scope() as db:
tasks = db_tasks.get_all(task_type=ArchiveMigrationTask, session=db, json_safe=True)
fields = [
'id',
'state',
'started_at',
'ended_at',
'migrate_from_driver',
'migrate_to_driver',
'archive_documents_migrated',
'archive_documents_to_migrate',
'last_updated'
]
headers = [
'id',
'state',
'start time',
'end time',
'from',
'to',
'migrated count',
'total to migrate',
'last updated'
]
tbl = PrettyTable(field_names=headers)
tbl.set_style(PLAIN_COLUMNS)
for t in tasks:
tbl.add_row([t[x] for x in fields])
logger.info((tbl.get_string(sortby='id')))