indent

mdtools.file_handler.indent(text, amount, char=' ')[source]

Indent a text by a given amount.

Pad every line of text with as many instances of char as given by amount. Lines in text are identified by Python’s string method str.splitlines().

Parameters:
  • text (str) – String to be indented.

  • amount (int) – Pad every line of text by this many instances of char. Negative values are treated as zero.

  • char (str, optional) – The string to be used as padding.

Returns:

indented_text (str) – The input text with every line padded by the given amount of padding characters.

Examples

>>> s = "Hello, World!\n  It's me, Mario!"
>>> print(s)
Hello, World!
  It's me, Mario!
>>> print(mdt.fh.indent(s, amount=4))
    Hello, World!
      It's me, Mario!
>>> print(mdt.fh.indent(s, amount=1, char="# "))
# Hello, World!
#   It's me, Mario!