当前位置: 首页>>代码示例>>Python>>正文


Python prettytable.PrettyTable方法代码示例

本文整理汇总了Python中prettytable.PrettyTable方法的典型用法代码示例。如果您正苦于以下问题:Python prettytable.PrettyTable方法的具体用法?Python prettytable.PrettyTable怎么用?Python prettytable.PrettyTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在prettytable的用法示例。


在下文中一共展示了prettytable.PrettyTable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: node_list

# 需要导入模块: import prettytable [as 别名]
# 或者: from prettytable import PrettyTable [as 别名]
def node_list(ctx, output='table'):
    """List nodes."""
    nodelist = NodeList(ctx.obj['CLIENT']).invoke()

    if output == 'table':
        pt = PrettyTable()

        pt.field_names = [
            'Node Name', 'Status', 'CPUs', 'Memory', 'PXE MAC', 'Mgmt IP',
            'IPMI IP', 'Power State'
        ]

        for n in nodelist:
            pt.add_row([
                n['hostname'], n['status_name'], n['cpu_count'], n['memory'],
                n['boot_mac'], n['boot_ip'], n['power_address'],
                n['power_state']
            ])

        click.echo(pt)
    elif output == 'json':
        click.echo(json.dumps(nodelist)) 
开发者ID:airshipit,项目名称:drydock,代码行数:24,代码来源:commands.py

示例2: get_alive_proxy

# 需要导入模块: import prettytable [as 别名]
# 或者: from prettytable import PrettyTable [as 别名]
def get_alive_proxy(self, amount=0, delay=0):
        """
        从数据库中获取获取存活的代理
        :param amount: 取出的数量
        :param delay: 取出延时小于delay的代理
        """
        all_ips = self.session.query(Proxy)
        all_ips = all_ips.filter(Proxy.is_alive == "1")
        if int(delay):
            all_ips = all_ips.filter(Proxy.times < delay)
        all_ips = all_ips.order_by(Proxy.times)
        if int(amount):
            all_ips = all_ips.limit(amount)

        result = all_ips.all()
        # TODO:在Windows上要设置GBK编码,mac未测试。
        # Linux 上需要设置为UTF-8编码
        encoding = "UTF-8" if "linux" in platform.system().lower() else "GBK"
        x = prettytable.PrettyTable(encoding=encoding, field_names=["Proxy IP", "Location", "Proxy Type", "Delay (s)"],
                                    float_format=".2")
        for res in result:
            x.add_row([res.ip + ":" + res.port, res.location, res.proxy_type, float(res.times)])
        x.align = "l"
        print x
        print "[*] Total: {}".format(str(len(result))) 
开发者ID:lightless233,项目名称:Pansidong,代码行数:27,代码来源:ProxyManage.py

示例3: show_data

# 需要导入模块: import prettytable [as 别名]
# 或者: from prettytable import PrettyTable [as 别名]
def show_data(cls):
        """display stored data in table"""
        if not len(cls.select()):
            click.echo(highlight_text("No entry found !!!"))
            return

        table = PrettyTable()
        table.field_names = ["NAME", "UUID", "LAST UPDATED"]
        for entity in cls.select():
            entity_data = entity.get_detail_dict()
            last_update_time = arrow.get(
                entity_data["last_update_time"].astimezone(datetime.timezone.utc)
            ).humanize()
            table.add_row(
                [
                    highlight_text(entity_data["name"]),
                    highlight_text(entity_data["uuid"]),
                    highlight_text(last_update_time),
                ]
            )
        click.echo(table) 
开发者ID:nutanix,项目名称:calm-dsl,代码行数:23,代码来源:table_config.py

示例4: upgrade_check

# 需要导入模块: import prettytable [as 别名]
# 或者: from prettytable import PrettyTable [as 别名]
def upgrade_check(self):
        check_results = []

        t = prettytable.PrettyTable(['Upgrade Check Results'],
                                    hrules=prettytable.ALL)
        t.align = 'l'

        for name, method in self.check_methods.items():
            result = method()
            check_results.append(result)
            cell = (
                'Check: %(name)s\n'
                'Result: %(result)s\n'
                'Details: %(details)s' %
                {
                    'name': name,
                    'result': UPGRADE_CHECK_MSG_MAP[result.code],
                    'details': result.get_details(),
                }
            )
            t.add_row([cell])
        print(t)

        return max(res.code for res in check_results) 
开发者ID:openstack,项目名称:kuryr-kubernetes,代码行数:26,代码来源:status.py

示例5: shards

# 需要导入模块: import prettytable [as 别名]
# 或者: from prettytable import PrettyTable [as 别名]
def shards(self, ctx):
        """Get a list of shards"""
        table = PrettyTable()
        table.field_names = ["Shard-Id", "Latency", "Guilds", "Users"]
        shards = await self.bot.get_shards()
        for shard in sorted(shards, key=lambda s: s["id"]):
            latency = f"{round(shard['latency'] * 1000, 1)} ms"
            if (datetime.utcnow() - shard["seen"]) > timedelta(minutes=3):
                latency = "offline?"

            table.add_row([str(shard["id"]), latency, helpers.format_number(shard["guilds"]),
                           helpers.format_number(shard["users"])])

        pages = formatter.paginate(str(table))
        for page in pages:
            await ctx.send(f"```diff\n{page}```") 
开发者ID:Xenon-Bot,项目名称:xenon,代码行数:18,代码来源:basics.py

示例6: query

# 需要导入模块: import prettytable [as 别名]
# 或者: from prettytable import PrettyTable [as 别名]
def query(self, ctx, timeout: float = 0.5, *, expression: str):
        """
        Evaluate a single expression on all shards and return the results


        __Arguments__

        **expressions**: The expression
        """
        results = await self.bot.query(expression, timeout=timeout)
        table = PrettyTable()
        table.field_names = ["Shard-Id", "Result"]
        for shards, result in sorted(results, key=lambda r: sum(r[0])):
            table.add_row([", ".join([str(s) for s in shards]), result])

        pages = formatter.paginate(str(table))
        for page in pages:
            await ctx.send(f"```diff\n{page}```") 
开发者ID:Xenon-Bot,项目名称:xenon,代码行数:20,代码来源:admin.py

示例7: pretty_print

# 需要导入模块: import prettytable [as 别名]
# 或者: from prettytable import PrettyTable [as 别名]
def pretty_print(self):

        pt = PrettyTable()
        pt._set_field_names(self.header)
        for m in self.movies:
            pt.add_row(m)
        print(pt)

        print('输入编号获取剧情简介:')
        while True:
            raw = input('>> ')
            if raw in ('q', 'quit'):
                exit()
            try:
                num = int(raw)
            except ValueError:
                print('Invalid number.')
                continue

            if (num - 1) in range(len(self)):
                self._get_movie_summary(num)
            else:
                print('Invalid number.') 
开发者ID:protream,项目名称:iquery,代码行数:25,代码来源:movies.py

示例8: pretty_print

# 需要导入模块: import prettytable [as 别名]
# 或者: from prettytable import PrettyTable [as 别名]
def pretty_print(self):

        if not self._hospital:
            pt = PrettyTable()
            pt._set_field_names([self._city])
            for hospital in self.putian_hospitals_in_city:
                pt.add_row([colored.green(hospital)])
            print(pt)

        else:
            is_putian, field_name = False, self._city + self._hospital

            for hospital in self.putian_hospitals_in_city:
                pt = PrettyTable()
                if self._hospital in hospital:
                    is_putian, field_name = True, hospital
                    pt._set_field_names([field_name])
                    pt.add_row([colored.green(str(is_putian))])
                    print(pt) 
开发者ID:protream,项目名称:iquery,代码行数:21,代码来源:hospitals.py

示例9: pretty_print

# 需要导入模块: import prettytable [as 别名]
# 或者: from prettytable import PrettyTable [as 别名]
def pretty_print(self):
        pt = PrettyTable()
        pt._set_field_names(self.header)
        # align left
        pt.align["开奖号码"] = "l"
        pt.align["奖池滚存(元)"] = "l"
        for item in self.lotteries:
            pt.add_row(item)
        print(pt)

        print('输入编号获取相应彩种往期中奖号码:')
        while True:
            raw = input('>> ')
            if raw in ('q', 'quit'):
                exit()
            try:
                num = int(raw)
            except ValueError:
                print('Invalid number.请按编号栏输入编号')
                continue

            if (num - 1) in range(len(self._rows)):
                self.get_lottery_detail(num)
            else:
                print('Invalid number.') 
开发者ID:protream,项目名称:iquery,代码行数:27,代码来源:lottery.py

示例10: process

# 需要导入模块: import prettytable [as 别名]
# 或者: from prettytable import PrettyTable [as 别名]
def process(self, question, candidates=None, top_n=1, n_docs=5):
        predictions = self.DrQA.process(
            question, candidates, top_n, n_docs, return_context=True
        )
        table = prettytable.PrettyTable(
            ['Rank', 'Answer', 'Doc', 'Answer Score', 'Doc Score']
        )
        for i, p in enumerate(predictions, 1):
            table.add_row([i, p['span'], p['doc_id'],
                        '%.5g' % p['span_score'],
                        '%.5g' % p['doc_score']])
        print('Top Predictions:')
        print(table)
        print('\nContexts:')
        for p in predictions:
            text = p['context']['text']
            start = p['context']['start']
            end = p['context']['end']
            output = (text[:start] +
                    colored(text[start: end], 'green', attrs=['bold']) +
                    text[end:])
            print('[ Doc = %s ]' % p['doc_id'])
            print(output + '\n')
        return predictions 
开发者ID:ailabstw,项目名称:justcopy-backend,代码行数:26,代码来源:engine.py

示例11: process

# 需要导入模块: import prettytable [as 别名]
# 或者: from prettytable import PrettyTable [as 别名]
def process(question, candidates=None, top_n=1, n_docs=5):
    predictions = DrQA.process(
        question, candidates, top_n, n_docs, return_context=True
    )
    table = prettytable.PrettyTable(
        ['Rank', 'Answer', 'Doc', 'Answer Score', 'Doc Score']
    )
    for i, p in enumerate(predictions, 1):
        table.add_row([i, p['span'], p['doc_id'],
                       '%.5g' % p['span_score'],
                       '%.5g' % p['doc_score']])
    print('Top Predictions:')
    print(table)
    print('\nContexts:')
    for p in predictions:
        text = p['context']['text']
        start = p['context']['start']
        end = p['context']['end']
        output = (text[:start] +
                  colored(text[start: end], 'green', attrs=['bold']) +
                  text[end:])
        print('[ Doc = %s ]' % p['doc_id'])
        print(output + '\n') 
开发者ID:ailabstw,项目名称:justcopy-backend,代码行数:25,代码来源:interactive.py

示例12: make_table

# 需要导入模块: import prettytable [as 别名]
# 或者: from prettytable import PrettyTable [as 别名]
def make_table(header, align_map=None, rows=None):
    """ Wrapper for pretty table """
    table = PrettyTable()
    table.horizontal_char = table.vertical_char = table.junction_char = ' '
    try:
        table.field_names = header
    except Exception as err:
        print_(header)
        raise err
    if align_map:
        for field, align in zip(header, align_map):
            table.align[field] = align
    if rows:
        for row in rows:
            if len(row) < len(table.field_names):
                continue
            try:
                table.add_row(row)
            except Exception as err:
                print_('fields:', table.field_names)
                print_('row:', row)
                print_('rows:', rows)
                raise err
    return table 
开发者ID:strizhechenko,项目名称:netutils-linux,代码行数:26,代码来源:layout.py

示例13: ConfuseMatrix

# 需要导入模块: import prettytable [as 别名]
# 或者: from prettytable import PrettyTable [as 别名]
def ConfuseMatrix(reallist, prelist, dcix=data.exdixxt):
    '''
    :param reallist: 真实的类别列表
    :param prelist: 预测的类别列表
    :return: 输出混淆矩阵
    '''

    # 首先将字典的键值互换
    ruid = {}
    for jj in dcix:
        ruid[dcix[jj]] = jj

    zidian = Tom(reallist, prelist)
    lieming = sorted(zidian.keys())
    table = PT(['混淆矩阵'] + ['预测%s' % ruid[d] for d in lieming])
    for jj in lieming:
        table.add_row(['实际%s' % ruid[jj]] + [zidian[jj][kk] for kk in lieming])
    return table

#  计算F1度量的函数 
开发者ID:Anfany,项目名称:Machine-Learning-for-Beginner-by-Python3,代码行数:22,代码来源:CatBoost_Classify_adult.py

示例14: confusion

# 需要导入模块: import prettytable [as 别名]
# 或者: from prettytable import PrettyTable [as 别名]
def confusion(realy, outy, method='Sklearn'):
    mix = PrettyTable()
    type = sorted(list(set(realy.T[0])), reverse=True)
    mix.field_names = [method] + ['预测:%d类'%si for si in type]
    # 字典形式存储混淆矩阵数据
    cmdict = {}
    for jkj in type:
        cmdict[jkj] = []
        for hh in type:
            hu = len(['0' for jj in range(len(realy)) if realy[jj][0] == jkj and outy[jj][0] == hh])
            cmdict[jkj].append(hu)
    # 输出表格
    for fu in type:
        mix.add_row(['真实:%d类'%fu] + cmdict[fu])
    return mix


# 将独热编码的类别变为标识为1,2,3的类别 
开发者ID:Anfany,项目名称:Machine-Learning-for-Beginner-by-Python3,代码行数:20,代码来源:Softmax_Sklearn.py

示例15: confusion

# 需要导入模块: import prettytable [as 别名]
# 或者: from prettytable import PrettyTable [as 别名]
def confusion(realy, outy, method='TensorFlow'):
    mix = PrettyTable()
    type = sorted(list(set(realy.T[0])), reverse=True)
    mix.field_names = [method] + ['预测:%d类'%si for si in type]
    # 字典形式存储混淆矩阵数据
    cmdict = {}
    for jkj in type:
        cmdict[jkj] = []
        for hh in type:
            hu = len(['0' for jj in range(len(realy)) if realy[jj][0] == jkj and outy[jj][0] == hh])
            cmdict[jkj].append(hu)
    # 输出表格
    for fu in type:
        mix.add_row(['真实:%d类'%fu] + cmdict[fu])
    return mix
# 将独热编码的类别变为标识为1,2,3的类别 
开发者ID:Anfany,项目名称:Machine-Learning-for-Beginner-by-Python3,代码行数:18,代码来源:Softmax_TensorFlow.py


注:本文中的prettytable.PrettyTable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。