Discuss / Python / 碰过这样的错误,空格问题。

碰过这样的错误,空格问题。

Topic source

Eliefly

#1 Created at ... [Delete] [Delete and Lock User]
def fact(n):
    '''
    >>> fact(0)
    Traceback (most recent call last):
        ...
    ValueError
    >>> fact(10)
    3628800
    >>> fact(5)
    120
    >>> fact(6)
    720
    '''
    if n < 1:
        raise ValueError()
    if n == 1:
        return 1
    return n * fact(n - 1)

if __name__ == '__main__':
    import doctest
    doctest.testmod()
D:\Python35\python.exe D:/Python35/Project/test.py
Traceback (most recent call last):
  File "D:/Python35/Project/test.py", line 22, in <module>
    doctest.testmod()
  File "D:\Python35\lib\doctest.py", line 1940, in testmod
    for test in finder.find(m, name, globs=globs, extraglobs=extraglobs):
  File "D:\Python35\lib\doctest.py", line 923, in find
    self._find(tests, obj, name, module, source_lines, globs, {})
  File "D:\Python35\lib\doctest.py", line 986, in _find
    globs, seen)
  File "D:\Python35\lib\doctest.py", line 973, in _find
    test = self._get_test(obj, name, module, globs, source_lines)
  File "D:\Python35\lib\doctest.py", line 1057, in _get_test
    filename, lineno)
  File "D:\Python35\lib\doctest.py", line 659, in get_doctest
    return DocTest(self.get_examples(string, name), globs,
  File "D:\Python35\lib\doctest.py", line 673, in get_examples
    return [x for x in self.parse(string, name)
  File "D:\Python35\lib\doctest.py", line 635, in parse
    self._parse_example(m, name, lineno)
  File "D:\Python35\lib\doctest.py", line 705, in _parse_example
    lineno + len(source_lines))
  File "D:\Python35\lib\doctest.py", line 791, in _check_prefix
    (lineno+i+1, name, line))
ValueError: line 3 of the docstring for __main__.fact has inconsistent leading whitespace: 'Traceback (most recent call last):'

Process finished with exit code 1

果真是空格问题


  • 1

Reply