indent function

(Shortest import: from brian2.utils.stringtools import indent)

brian2.utils.stringtools.indent(text, numtabs=1, spacespertab=4, tab=None)[source]

Indents a given multiline string.

By default, indentation is done using spaces rather than tab characters. To use tab characters, specify the tab character explictly, e.g.:

indent(text, tab='      ')

Note that in this case spacespertab is ignored.

Examples

>>> multiline = '''def f(x):
...     return x*x'''
>>> print(multiline)
def f(x):
    return x*x
>>> print(indent(multiline))
    def f(x):
        return x*x
>>> print(indent(multiline, numtabs=2))
        def f(x):
            return x*x
>>> print(indent(multiline, spacespertab=2))
  def f(x):
      return x*x
>>> print(indent(multiline, tab='####'))
####def f(x):
####    return x*x