Possible to include \n chars in doctest code samples or output?
Thomas Jollans
thomas at jollans.com
Fri Jul 16 12:45:03 EDT 2010
On 07/16/2010 07:26 AM, python at bdurham.com wrote:
> Thomas,
>
>> Recall that doctest doesn't parse the code, it extracts the docstrings. And docstrings are just strings, and are parsed like strings.
>
> I understand what you're saying, but I'm struggling with how to
> represent the following strings in doctest code and doctest results. No
> matter what combination of backslashes or raw strings I use, I am unable
> to find a way to code the following.
>
>>>> encode( '", \, \t, \n' )
> '\", \\, \\t, \\n'
Does either of these docstrings work:
def encode(s):
"""description
>>> encode( '", \\, \\t, \\n' )
'\\", \\\\, \\\\t, \\\\n'
"""
...
def encode(s):
r"""description
>>> encode( '", \, \t, \n' )
'\", \\, \\t, \\n'
"""
...
More information about the Python-list
mailing list