python中出現IndentationError:unindent does not match any outer indentation level錯誤

來源:互聯網
上載者:User

標籤:src   包含   notepad++   注意   track   outer   func   python   for   

python中出現IndentationError:unindent does not match any outer indentation level

今天在網上copy的一段代碼。代碼非常easy,每行看起來該縮排的都縮排了。執行的時候出現了例如以下錯誤:

【解決過程】
1.對於此錯誤,最常見的原因是,的確沒有縮排。

依據錯誤提示的行數,去代碼中看了下,看起來沒有什麼問題呀,都有縮排。並且文法也沒有錯誤呀。

2.細緻研究了下代碼,發現真的看不出什麼問題。突然想到了,把當前python指令碼的全部字元(包含空格和tab字元)都顯示出來看看究竟有沒有縮排或者是其它特殊的字元。

當前用的文字編輯器Notepad++,有個設定,能夠顯示全部的字元的。
在:
視圖 –> 顯示符號 –> 顯示空格與定位字元
這樣就能夠看到我們Python代碼的究竟有沒有該縮排的都縮排了。

終於發現代碼報錯原因還真是出在這裡,錯誤提示的這行看起來是縮排了。實際上確沒有縮排,這就是問題的根源所在。

發現了個問題。發現copy過來的Python代碼都沒有進行縮排,當我們copy別人的代碼時,縮排這點須要額外注意。不要看起來代碼縮排了就感覺ok了,實際上是沒有縮排的。

python中出現IndentationError:unindent does not match any outer indentation level錯誤

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.