MCPcopy Create free account
hub / github.com/ipython/ipython / PlainTextFormatter

Class PlainTextFormatter

IPython/core/formatters.py:567–704  ·  view source on GitHub ↗

The default pretty-printer. This uses :mod:`IPython.lib.pretty` to compute the format data of the object. If the object cannot be pretty printed, :func:`repr` is used. See the documentation of :mod:`IPython.lib.pretty` for details on how to write pretty printers. Here is a simple e

Source from the content-addressed store, hash-verified

565
566
567class PlainTextFormatter(BaseFormatter):
568 """The default pretty-printer.
569
570 This uses :mod:`IPython.lib.pretty` to compute the format data of
571 the object. If the object cannot be pretty printed, :func:`repr` is used.
572 See the documentation of :mod:`IPython.lib.pretty` for details on
573 how to write pretty printers. Here is a simple example::
574
575 def dtype_pprinter(obj, p, cycle):
576 if cycle:
577 return p.text('dtype(...)')
578 if hasattr(obj, 'fields'):
579 if obj.fields is None:
580 p.text(repr(obj))
581 else:
582 p.begin_group(7, 'dtype([')
583 for i, field in enumerate(obj.descr):
584 if i > 0:
585 p.text(',')
586 p.breakable()
587 p.pretty(field)
588 p.end_group(7, '])')
589 """
590
591 # The format type of data returned.
592 format_type = Unicode('text/plain')
593
594 # This subclass ignores this attribute as it always need to return
595 # something.
596 enabled = Bool(True).tag(config=False)
597
598 max_seq_length = Integer(pretty.MAX_SEQ_LENGTH,
599 help="""Truncate large collections (lists, dicts, tuples, sets) to this size.
600
601 Set to 0 to disable truncation.
602 """
603 ).tag(config=True)
604
605 # Look for a _repr_pretty_ methods to use for pretty printing.
606 print_method = ObjectName('_repr_pretty_')
607
608 # Whether to pretty-print or not.
609 pprint = Bool(True).tag(config=True)
610
611 # Whether to be verbose or not.
612 verbose = Bool(False).tag(config=True)
613
614 # The maximum width.
615 max_width = Integer(79).tag(config=True)
616
617 # The newline character.
618 newline = Unicode('\n').tag(config=True)
619
620 # format-string for pprinting floats
621 float_format = Unicode('%r')
622 # setter for float precision, either int or direct format-string
623 float_precision = CUnicode('').tag(config=True)
624

Callers 15

test_prettyFunction · 0.90
test_deferredFunction · 0.90
test_precisionFunction · 0.90
test_bad_precisionFunction · 0.90
test_for_typeFunction · 0.90
test_for_type_stringFunction · 0.90
test_for_type_by_nameFunction · 0.90
test_lookupFunction · 0.90
test_lookup_stringFunction · 0.90
test_lookup_by_typeFunction · 0.90
test_in_formatterFunction · 0.90

Calls

no outgoing calls

Tested by 15

test_prettyFunction · 0.72
test_deferredFunction · 0.72
test_precisionFunction · 0.72
test_bad_precisionFunction · 0.72
test_for_typeFunction · 0.72
test_for_type_stringFunction · 0.72
test_for_type_by_nameFunction · 0.72
test_lookupFunction · 0.72
test_lookup_stringFunction · 0.72
test_lookup_by_typeFunction · 0.72
test_in_formatterFunction · 0.72