Defines the Formatter class

Module Contents



Class defining the formatting rules for an object

class, stringreplacers=None, regexreplace=None, formatstring='%s', ebstring='%s +/- %s', nmebstring=None, stringreturn=None, defaults=None)

Bases: object

Class defining the formatting rules for an object

Once created, is used like a function with the signature: item, specs -> string See __call__ method for details

__call__ could be renamed to render() for compatibility with table.render(), row.render(), etc.. However, using __call__ allows for the user to drop in custom functions in place of Formatter objects, which is useful (i.e. in creating figure formatters)

  • custom (function, optional) – A custom-formatting function that has signature custom(item, specs) and returns item formatted as a string.

  • stringreplacers (tuple, optional) – A tuple of tuples of the form (pattern, replacement) where replacement is a normal string. Ex : [(‘rho’, ‘ρ’)]

  • regexreplace (tuple, optional) – A tuple of the form (regex, replacement) where replacement is formattable string, and gets formatted with grouped result of regex matching on item) Ex : (‘.*?([0-9]+)$’, ‘_{%s}’)

  • formatstring (str, optional) – Outer formatting for after both replacements have been made

  • ebstring (str, optional) – Format string used if the item being formatted has attached error bars.

  • nmebstring (str, optional) – Alternate format string to use for non-Markovian error bars.

  • stringreturn (tuple) – A (string, string) tuple that creates a formatting rules where the the second string is used if a label is equal to the first.

  • defaults (dictionary (string, any)) – overriden values to the dictionary passed in during formatted. ie for rounded formatters, which override the precision key to be set to two

__call__(self, item, specs)

Formatting function template

  • item (string, the item to be formatted!) –

  • specs (dictionary) – dictionary of options to be sent to the formatter and custom functions


formatted item (string)

variant(self, **kwargs)

Create a Formatter object from an existing formatter object, tweaking it slightly.


kwargs (various) – Arguments to Formatter.__init__().