在下面的代码块中
def classify0(inx, ds, ls, k):
sdindices = dist.argsort()
clcount = {}
for i in range(k):
vlab = ls[sdindices[i]]
clcount[vlab] = clcount.get(vlab,0)+1
sclcount = sorted(clcount.iteritems(), key=operator.itemgetter(1), reverse=True)
# Previous lines gives: IndentationError: unindent does not match any outer indentation level
return sclcount[0][0]
如评论所示,以
开头的行sclcount = "
给出缩进错误。现在我已经检查了所有“通常的嫌疑人”:没有制表符和正确的空格数。
此外,我正在使用 PyCharm (/intellij) 并且没有警告/语法错误。仅在 python shell 中..
看起来 ipython 中的 %cpaste (或 %paste)解决了这个问题。