Mein Code gibt eine Ausnahme von einer Docstring, und ich kann das Problem nicht sehen:Einfache Python-Dokumentation Ausnahme
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()
Fehler:
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]
Wenn die Dokumentation Zeichenfolge auf Kommentar in Die Dokumentationszeichenfolge printWords funktioniert, der Code funktioniert. Ich erwarte, dass es etwas Einfaches ist, aber ich sehe es nicht.
Danke!