2013-05-06 106 views
0

我在下面的代碼中不斷收到「lijst2 = lijst + [cat]」這一行的錯誤「意外縮進」。我不知道爲什麼,因爲據我所見,縮進似乎是正確的?請記住我是初學者。謝謝!這是我的代碼:意外的縮進Python

for fileid in corpus.fileids(): 
    tekst1 = corpus.words(fileid) 
    instantie = defaultdict(float) 
    cat = mijn_corpus.fileids() 
    for word in tekst1: 
     if word in freq: 
      instantie[word] +=1  
    for word in freq: 
     if word not in tekst1: 
      instantie[word] +=0 
    lijst1 = [] 
    for key, value in instantie.iteritems(): 
     lijst1.append(value) 
     lijst2 = lijst + [cat] # Here I get the error message: unexpected indent 
     resultaten.writerrow(lijst2) 
+9

你可能混合空格和製表符。 – sloth 2013-05-06 08:58:02

+0

看起來'lijst'應該是'lijst1'。如果您評論該行,該怎麼辦? – konjac 2013-05-06 08:59:11

+2

從[PEP-8風格指南](http://www.python.org/dev/peps/pep-0008/#tabs-or-spaces) - 切勿混合製表符和空格。 – 2013-05-06 08:59:12

回答

7

你混合空格和製表符。

例如,該行resultaten.writerrow(lijst2)開始於一個標籤,而所有其他線與空間(你甚至它複製到你的問題)開始。

更好地利用一個編輯器,顯示了這種特徵:

enter image description here

+4

...或將標籤自動更改爲空格的編輯器 – 2013-05-06 09:02:32

+0

偉大的問題解決!非常感謝! :) – JohnDoe 2013-05-06 12:01:22