deindent function

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

brian2.utils.stringtools.deindent(text, numtabs=None, spacespertab=4, docstring=False)[source]

Returns a copy of the string with the common indentation removed.

Note that all tab characters are replaced with spacespertab spaces.

If the docstring flag is set, the first line is treated differently and is assumed to be already correctly tabulated.

If the numtabs option is given, the amount of indentation to remove is given explicitly and not the common indentation.

Examples

Normal strings, e.g. function definitions:

>>> multiline = """    def f(x):
...          return x**2"""
>>> print(multiline)
    def f(x):
         return x**2
>>> print(deindent(multiline))
def f(x):
     return x**2
>>> print(deindent(multiline, docstring=True))
    def f(x):
return x**2
>>> print(deindent(multiline, numtabs=1, spacespertab=2))
  def f(x):
       return x**2

Docstrings:

>>> docstring = """First docstring line.
...     This line determines the indentation."""
>>> print(docstring)
First docstring line.
    This line determines the indentation.
>>> print(deindent(docstring, docstring=True))
First docstring line.
This line determines the indentation.