在下面的代码:文档字符串有不一致的前导空格
def read_file(filename):
"""
>>> read_file('text.txt')
{'Donald Trump': [('Donald Trump', 'Join me live in Springfield, Ohio!\nLit!!\n', 1477604720, 'Twitter for iPhone', 5251, 1895)]}
"""
我得到一个错误说:
ValueError: line 4 of the docstring for __main__.read_file has inconsistent leading whitespace: 'Lit!!'
任何想法是什么原因造成的?
凡被触发错误?看起来你正在运行doctests。正如某人已经回答的那样,问题在于测试数据中的那些未转义的新行。但无论如何,doctests对于有副作用的功能来说并不是最佳的。如果找不到'text.txt',或者内容与期望的不同,则此测试将失败。 –