How can I include special characters (tab, newline) in a python doctest result string?

后端 未结 6 1520
甜味超标
甜味超标 2021-02-18 19:06

Given the following python script:

# dedupe.py
import re

def dedupe_whitespace(s,spacechars=\'\\t \'):
    \"\"\"Merge repeated whitespace characters.
    Examp         


        
6条回答
  •  旧时难觅i
    2021-02-18 19:43

    I got it to work by escaping the tab character in the expected string:

    >>> function_that_returns_tabbed_text()
    '\\t\\t\\tsometext\\t\\t'
    

    instead of

    >>> function_that_returns_tabbed_text()
    \t\t\tsometext\t\t
    

提交回复
热议问题