Python 未缩进错误仅在 python REPL 中,即使具有正确的空格数(并且没有制表符)[重复]

问题描述 投票:0回答:1

在下面的代码块中

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 中..

python indentation
1个回答
1
投票

看起来 ipython 中的 %cpaste (或 %paste)解决了这个问题。

© www.soinside.com 2019 - 2024. All rights reserved.