You are viewing an older version (9.10.0). Go to latest (9.13.0)
{ } Raw JSON

bundles / IPython 9.10.0 / IPython / utils / text / EvalFormatter

class

IPython.utils.text:EvalFormatter

source: /IPython/utils/text.py :432

Signature

class   EvalFormatter ( )

Members

Summary

A String Formatter that allows evaluation of simple expressions.

Extended Summary

Note that this version interprets a : as specifying a format string (as per standard string formatting), so if slicing is required, you must explicitly create a slice.

Note that on Python 3.14+ this version interprets [] as indexing operator so you need to use generators instead of list comprehensions, for example: list(i for i in range(10)).

This is to be used in templating cases, such as the parallel batch script templates, where simple arithmetic on arguments is useful.

Examples

:: In [1]: f = EvalFormatter() In [2]: f.format('{n//4}', n=8) Out[2]: '2' In [3]: f.format("{greeting[slice(2,4)]}", greeting="Hello") Out[3]: 'll'

Aliases

  • IPython.utils.text.EvalFormatter