Hi all. My question is simple. When you guys write Python doctests, how do you go about introducing the newline characters in the string while testing the process?
Check out the following example:
def remove_newlines(text):
"""
>>> remove_newlines("line1 \n"
... "still line 1\r"
... "now line2 \n"
... "more line2\n")
line1 still line1
now line2 more line2
"""
return text.replace('\n', '')
import doctest
doctest.run_docstring_examples(remove_newlines, globals())
The output is something like this:
Traceback (most recent call last):
...
ValueError: line 3 of the docstring for NoName has inconsistent leading whitespace: '"'
What am I missing here lads? Using this in a project of mine and I could appreciate all the help that I could get!