dedent

odl.util.utility.dedent(string, indent_str='   ', max_levels=None)[source]

Revert the effect of indentation.

Examples

Remove a simple one-level indentation:

>>> text = '''<->This is line 1.
... <->Next line.
... <->And another one.'''
>>> print(text)
<->This is line 1.
<->Next line.
<->And another one.
>>> print(dedent(text, '<->'))
This is line 1.
Next line.
And another one.

Multiple levels of indentation:

>>> text = '''<->Level 1.
... <-><->Level 2.
... <-><-><->Level 3.'''
>>> print(text)
<->Level 1.
<-><->Level 2.
<-><-><->Level 3.
>>> print(dedent(text, '<->'))
Level 1.
<->Level 2.
<-><->Level 3.
>>> text = '''<-><->Level 2.
... <-><-><->Level 3.'''
>>> print(text)
<-><->Level 2.
<-><-><->Level 3.
>>> print(dedent(text, '<->'))
Level 2.
<->Level 3.
>>> print(dedent(text, '<->', max_levels=1))
<->Level 2.
<-><->Level 3.