Utility functions for pretty-printing#

These utility functions are used in the implementations of _repr_ methods elsewhere.

class sage.repl.display.util.TallListFormatter#

Bases: object

Special representation for lists with tall entries (e.g. matrices)


Return “tall list” string representation.

See also try_format().


  • the_list – list or tuple.




sage: from sage.repl.display.util import format_list
sage: format_list(['not', 'tall'])
"['not', 'tall']"

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.


  • the_list - The list (or a tuple).


String or None. The latter is returned if the list is not deemed to be tall enough and another formatter should be used.