### Navigation

- index
- modules |
- next |
- previous |
- The Sage Command Line »

# 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)

  `__call__`(the_list)

    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']"

  `try_format`(the_list)

    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.

    TESTS:

        sage: from sage.repl.display.util import format_list
        sage: print format_list.try_format(
        ....:        [matrix([[1, 2, 3, 4], [5, 6, 7, 8]]) for i in xrange(7)])
        [
        [1 2 3 4]  [1 2 3 4]  [1 2 3 4]  [1 2 3 4]  [1 2 3 4]  [1 2 3 4]
        [5 6 7 8], [5 6 7 8], [5 6 7 8], [5 6 7 8], [5 6 7 8], [5 6 7 8],
        <BLANKLINE>
        [1 2 3 4]
        [5 6 7 8]
        ]

        sage: format_list.try_format(['not', 'tall']) is None
        True

### Navigation

- index
- modules |
- next |
- previous |
- The Sage Command Line »