當前位置: 首頁>>代碼示例>>Python>>正文


Python pprint.PrettyPrinter方法代碼示例

本文整理匯總了Python中pprint.PrettyPrinter方法的典型用法代碼示例。如果您正苦於以下問題:Python pprint.PrettyPrinter方法的具體用法?Python pprint.PrettyPrinter怎麽用?Python pprint.PrettyPrinter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pprint的用法示例。


在下文中一共展示了pprint.PrettyPrinter方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_range_aggregation

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import PrettyPrinter [as 別名]
def test_range_aggregation(self):
        """Test 1 tier range aggregation"""
        keys = [RangeKeyAggregator(ranges=[10, 20, 30, 40, 50], key='rtt')]
        buckets = aggregate(self.results, keys)
        expected_output = {
            'RTT: 10-20': [self.Result(id=5, probe=self.Probe(id=5, country='SE', asn=337, status='DisConnected'), rtt=17, source='127.0.0.1', prefix='192/8'), self.Result(id=6, probe=self.Probe(id=6, country='SE', asn=335, status='DisConnected'), rtt=15, source='127.0.0.1', prefix='195/8')],
            'RTT: 20-30': [self.Result(id=8, probe=self.Probe(id=8, country='DE', asn=338, status='Connected'), rtt=28, source='127.0.0.1', prefix='192/8'), self.Result(id=10, probe=self.Probe(id=10, country='DE', asn=338, status='NeverConnected'), rtt=28, source='127.0.0.1', prefix='194/8')],
            'RTT: 30-40': [self.Result(id=2, probe=self.Probe(id=2, country='NL', asn=334, status='Connected'), rtt=34.0, source='127.0.0.1', prefix='192/8'), self.Result(id=3, probe=self.Probe(id=3, country='SE', asn=335, status='Connected'), rtt=35.0, source='127.0.0.1', prefix='193/8'), self.Result(id=7, probe=self.Probe(id=7, country='IN', asn=335, status='Connected'), rtt=35, source='127.0.0.1', prefix='192/8'), self.Result(id=11, probe=self.Probe(id=11, country='DE', asn=340, status='DisConnected'), rtt=40, source='127.0.0.1', prefix='193/8')],
            'RTT: 40-50': [self.Result(id=9, probe=self.Probe(id=9, country='DK', asn=348, status='Connected'), rtt=48, source='127.0.0.1', prefix='195/8')],
            'RTT: < 10': [self.Result(id=1, probe=self.Probe(id=1, country='GR', asn=333, status='Connected'), rtt=3, source='127.0.0.1', prefix='192/8'), self.Result(id=4, probe=self.Probe(id=4, country='SE', asn=336, status='DisConnected'), rtt=6, source='127.0.0.1', prefix='193/8')]
        }
        self.maxDiff = None
        import pprint
        pp = pprint.PrettyPrinter()
        pp.pprint(buckets)
        self.assertEquals(buckets, expected_output) 
開發者ID:RIPE-NCC,項目名稱:ripe-atlas-tools,代碼行數:18,代碼來源:test_aggregators.py

示例2: pretty_print_objects

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import PrettyPrinter [as 別名]
def pretty_print_objects(self):
        """ Print a flat list of objects in the table.

        >>> t = Table()
        >>> t.append_column("FirstName")
        >>> t.append_column("LastName")
        >>> t.append_row( ["Curtis", "Lassam"] )
        >>> t.append_row( ["Jonathan", "Lassam"] )
        >>> t.pretty_print_objects()
        {   'FirstName': 'Curtis',
            'LastName': 'Lassam'}
        -------------------
        {   'FirstName': 'Jonathan',
            'LastName': 'Lassam'}
        -------------------

        """
        pretty_print = pprint.PrettyPrinter(indent=4,width=10)
        list_of_strings = []
        for row_map in self.row_maps():
            pretty_print.pprint(row_map)
            print("-------------------") 
開發者ID:sfu-fas,項目名稱:coursys,代碼行數:24,代碼來源:table.py

示例3: main

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import PrettyPrinter [as 別名]
def main():
    import warnings
    warnings.filterwarnings("ignore")

    print('inference similarities of whales')
    args = parse_args()
    if args.config_file is None:
      raise Exception('no configuration file')

    config = utils.config.load(args.config_file)
    pprint.PrettyPrinter(indent=2).pprint(config)
    dir_name = os.path.dirname(args.output_path)
    os.makedirs(dir_name, exist_ok=True)
    run(config,
        tta_flip=args.tta_flip==1,
        tta_landmark=args.tta_landmark==1,
        checkpoint_name=args.checkpoint_name,
        output_path=args.output_path)
    print('success!') 
開發者ID:pudae,項目名稱:kaggle-humpback,代碼行數:21,代碼來源:inference_similarity.py

示例4: get_config

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import PrettyPrinter [as 別名]
def get_config(self, verbose=0):
        config = super(Model, self).get_config()
        for p in ['class_mode', 'theano_mode']:
            if hasattr(self, p):
                config[p] = getattr(self, p)
        if hasattr(self, 'optimizer'):
            config['optimizer'] = self.optimizer.get_config()
        if hasattr(self, 'loss'):
            if type(self.loss) == dict:
                config['loss'] = dict([(k, get_function_name(v)) for k, v in self.loss.items()])
            else:
                config['loss'] = get_function_name(self.loss)

        if verbose:
            pp = pprint.PrettyPrinter(indent=4)
            pp.pprint(config)
        return config 
開發者ID:lllcho,項目名稱:CAPTCHA-breaking,代碼行數:19,代碼來源:models.py

示例5: Dump

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import PrettyPrinter [as 別名]
def Dump(self, key = None):
        """
        Using the standard Python pretty printer, return the contents of the
        scons build environment as a string.

        If the key passed in is anything other than None, then that will
        be used as an index into the build environment dictionary and
        whatever is found there will be fed into the pretty printer. Note
        that this key is case sensitive.
        """
        import pprint
        pp = pprint.PrettyPrinter(indent=2)
        if key:
            dict = self.Dictionary(key)
        else:
            dict = self.Dictionary()
        return pp.pformat(dict) 
開發者ID:Autodesk,項目名稱:arnold-usd,代碼行數:19,代碼來源:Environment.py

示例6: test_basic

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import PrettyPrinter [as 別名]
def test_basic(self):
        # Verify .isrecursive() and .isreadable() w/o recursion
        pp = pprint.PrettyPrinter()
        for safe in (2, 2.0, 2j, "abc", [3], (2,2), {3: 3}, uni("yaddayadda"),
                     bytearray(b"ghi"), True, False, None,
                     self.a, self.b):
            # module-level convenience functions
            self.assertFalse(pprint.isrecursive(safe),
                             "expected not isrecursive for %r" % (safe,))
            self.assertTrue(pprint.isreadable(safe),
                            "expected isreadable for %r" % (safe,))
            # PrettyPrinter methods
            self.assertFalse(pp.isrecursive(safe),
                             "expected not isrecursive for %r" % (safe,))
            self.assertTrue(pp.isreadable(safe),
                            "expected isreadable for %r" % (safe,)) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:18,代碼來源:test_pprint.py

示例7: main

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import PrettyPrinter [as 別名]
def main():
  backend_opset_dict = {}

  for schema in defs.get_all_schemas():
    op_name = schema.name
    backend_opset_dict[op_name] = []

  backend_onnx_coverage, backend_experimental_op = get_backend_coverage()
  backend_opset_dict.update(backend_onnx_coverage.get(defs.ONNX_DOMAIN, {}))
  backend_ps_dict = get_backend_partial_support_detail()

  with open('opset_version.py', 'w') as version_file:
    pp = pprint.PrettyPrinter(indent=4)
    version_file.write("backend_opset_version = {\n " +
                       pp.pformat(backend_opset_dict)[1:-1] + "\n}\n\n")
    version_file.write("backend_partial_support = {\n " +
                       pp.pformat(backend_ps_dict)[1:-1] + "\n}\n") 
開發者ID:onnx,項目名稱:onnx-tensorflow,代碼行數:19,代碼來源:gen_opset.py

示例8: _pprint_key_val_tuple

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import PrettyPrinter [as 別名]
def _pprint_key_val_tuple(self, object, stream, indent, allowance, context,
                              level):
        """Pretty printing for key-value tuples from dict or parameters."""
        k, v = object
        rep = self._repr(k, context, level)
        if isinstance(object, KeyValTupleParam):
            rep = rep.strip("'")
            middle = '='
        else:
            middle = ': '
        stream.write(rep)
        stream.write(middle)
        self._format(v, stream, indent + len(rep) + len(middle), allowance,
                     context, level)

    # Note: need to copy _dispatch to prevent instances of the builtin
    # PrettyPrinter class to call methods of _EstimatorPrettyPrinter (see issue
    # 12906) 
開發者ID:scikit-multiflow,項目名稱:scikit-multiflow,代碼行數:20,代碼來源:_pprint.py

示例9: main

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import PrettyPrinter [as 別名]
def main(args):
    if len(args) != 2:
        sys.exit(1)

    pp = pprint.PrettyPrinter(indent="2")

    f = codecs.open(args[1], encoding='utf-8')
    s = f.readline()

    s = normalize_input(s)

    try:
        d = yaml.load(s)
    except Exception as err:
        print "Failed to load as yaml: "
        print err.message

    print json.dumps(d, indent=4) 
開發者ID:F5Networks,項目名稱:f5-openstack-agent,代碼行數:20,代碼來源:convert_service.py

示例10: Dump

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import PrettyPrinter [as 別名]
def Dump(self, key = None):
        """
        Using the standard Python pretty printer, dump the contents of the
        scons build environment to stdout.

        If the key passed in is anything other than None, then that will
        be used as an index into the build environment dictionary and
        whatever is found there will be fed into the pretty printer. Note
        that this key is case sensitive.
        """
        import pprint
        pp = pprint.PrettyPrinter(indent=2)
        if key:
            dict = self.Dictionary(key)
        else:
            dict = self.Dictionary()
        return pp.pformat(dict) 
開發者ID:coin3d,項目名稱:pivy,代碼行數:19,代碼來源:Environment.py

示例11: oprint

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import PrettyPrinter [as 別名]
def oprint(self, input_txt, **options):
        source = self.options['source']

        if 'source' in options.keys():
            source = '{0} : {1}'.format(source, options.pop('source'))

        self.configure(**options)

        self.pp = pprint.PrettyPrinter(indent=self.options['indent'], width=self.options['width'], compact=True)

        header = self.options['seperator_line'].format(
            source='[{0}]'.format(source), char=self.options['seperator_char'], width=self.options['width']
        )
        footer = self.options['seperator_char'] * self.options['width']

        sys.stdout.write(self.colorize(header))
        sys.stdout.write('\n')
        self.pp.pprint(input_txt)
        sys.stdout.write(self.colorize(footer))
        sys.stdout.write('\n' * 2) 
開發者ID:vigo,項目名稱:django2-project-template,代碼行數:22,代碼來源:console.py

示例12: templates

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import PrettyPrinter [as 別名]
def templates(ctx, input_file, check, update, diff, name, template_type):
    """
    Import templates from file
    """
    vmanage_files = Files(ctx.auth, ctx.host)
    pp = pprint.PrettyPrinter(indent=2)

    click.echo(f'Importing templates from {input_file}')
    result = vmanage_files.import_templates_from_file(input_file,
                                                      update=update,
                                                      check_mode=check,
                                                      name_list=name,
                                                      template_type=template_type)
    print(f"Feature Template Updates: {len(result['feature_template_updates'])}")
    if diff:
        for diff_item in result['feature_template_updates']:
            click.echo(f"{diff_item['name']}:")
            pp.pprint(diff_item['diff'])
    print(f"Device Template Updates: {len(result['device_template_updates'])}")
    if diff:
        for diff_item in result['device_template_updates']:
            click.echo(f"{diff_item['name']}:")
            pp.pprint(diff_item['diff']) 
開發者ID:CiscoDevNet,項目名稱:python-viptela,代碼行數:25,代碼來源:templates.py

示例13: definition

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import PrettyPrinter [as 別名]
def definition(ctx, name, json, definition_type):  #pylint: disable=unused-argument
    """
    Show policy definition information
    """
    policy_definitions = PolicyDefinitions(ctx.auth, ctx.host)
    policy_data = PolicyData(ctx.auth, ctx.host)
    pp = pprint.PrettyPrinter(indent=2)

    if name:
        policy_definition_dict = policy_definitions.get_policy_definition_dict(definition_type)
        if name in policy_definition_dict:
            policy_definition = policy_data.export_policy_definition_list(policy_definition_dict[name]['type'].lower())
            # list_keys(policy_definition['definition'])
            pp.pprint(policy_definition)
    else:
        policy_definition_list = policy_data.export_policy_definition_list(definition_type)
        pp.pprint(policy_definition_list) 
開發者ID:CiscoDevNet,項目名稱:python-viptela,代碼行數:19,代碼來源:policies.py

示例14: central

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import PrettyPrinter [as 別名]
def central(ctx, name, json):  #pylint: disable=unused-argument
    """
    Show central policy information
    """
    central_policy = CentralPolicy(ctx.auth, ctx.host)
    policy_data = PolicyData(ctx.auth, ctx.host)
    pp = pprint.PrettyPrinter(indent=2)

    if name:
        central_policy_dict = central_policy.get_central_policy_dict()
        if name in central_policy_dict:
            if json:
                pp.pprint(central_policy_dict[name])
            else:
                preview = central_policy.get_central_policy_preview(central_policy_dict[name]['policyId'])
                pp.pprint(preview)
    else:
        central_policy_list = policy_data.export_central_policy_list()
        pp.pprint(central_policy_list) 
開發者ID:CiscoDevNet,項目名稱:python-viptela,代碼行數:21,代碼來源:policies.py

示例15: security

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import PrettyPrinter [as 別名]
def security(ctx, name, json):  #pylint: disable=unused-argument
    """
    Show security policy information
    """
    security_policy = SecurityPolicy(ctx.auth, ctx.host)
    policy_data = PolicyData(ctx.auth, ctx.host)
    pp = pprint.PrettyPrinter(indent=2)

    if name:
        security_policy_dict = security_policy.get_security_policy_dict()
        if name in security_policy_dict:
            if json:
                pp.pprint(security_policy_dict[name])
            else:
                preview = security_policy.get_security_policy_preview(security_policy_dict[name]['policyId'])
                pp.pprint(preview)
    else:
        security_policy_list = policy_data.export_security_policy_list()
        pp.pprint(security_policy_list) 
開發者ID:CiscoDevNet,項目名稱:python-viptela,代碼行數:21,代碼來源:policies.py


注:本文中的pprint.PrettyPrinter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。