Utility functions for pretty-printing¶
These utility functions are used in the implementations of _repr_
methods elsewhere.
- class sage.repl.display.util.TallListFormatter[source]¶
Bases:
object
Special representation for lists with tall entries (e.g. matrices).
- __call__(the_list)[source]¶
Return “tall list” string representation.
See also
try_format()
.INPUT:
the_list
– list or tuple
OUTPUT: string
EXAMPLES:
sage: from sage.repl.display.util import format_list sage: format_list(['not', 'tall']) "['not', 'tall']"
>>> from sage.all import * >>> from sage.repl.display.util import format_list >>> format_list(['not', 'tall']) "['not', 'tall']"
- MAX_COLUMN = 70¶
- try_format(the_list)[source]¶
First check whether a list is “tall” – whether the reprs of the elements of the list will span multiple lines and cause the list to be printed awkwardly. If not, this function returns
None
and does nothing; you should revert back to the normal method for printing an object (its repr). If so, return the string in the special format. Note that the special format isn’t just for matrices. Any object with a multiline repr will be formatted.INPUT:
the_list
– the list (or a tuple)
OUTPUT:
String or
None
. The latter is returned if the list is not deemed to be tall enough and another formatter should be used.