0
我的代码返回从文档字符串的例外,我看不出问题:简单的Python文档例外
def printBreak(title):
"""Prints a dotted line"""
print("------" + title + "------")
def printWords(theWords):
"""Prints the passed array with word length and word"""
for w in theWords:
print(len(w), w)
print("")
def sortWordsByLength(theWords):
"""Word array sorted by length"""
for w in theWords:
for i in range(len(wordsSortedByLength)):
if len(w) > len(wordsSortedByLength[i]):
wordsSortedByLength.insert(i,w)
break
else:
wordsSortedByLength.append(w)
def main():
printBreak("Initial word array")
printWords(words)
printBreak(sortWordsByLength.__doc__)
sortWordsByLength(words[1:])
printWords(wordsSortedByLength)
# Sort some strings
words = ['happy', 'cat', 'window', 'appetite', 'gophery', 'it', 'perky']
wordsSortedByLength = [words[0]]
main()
错误:
File "/Users/bevilacm/source/Python/Scripts/sortWords.py", line 7
for w in theWords:
^
IndentationError: unindent does not match any outer indentation level
[Finished in 0.1s with exit code 1]
如果文档字符串被注释掉printWords函数文档字符串,代码有效。我期望它是简单的东西,但我没有看到它。
谢谢!