亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么會出現“ IndentationError:預期為縮進塊”?

為什么會出現“ IndentationError:預期為縮進塊”?

米琪卡哇伊 2019-09-26 09:46:33
if len(trashed_files) == 0 :     print "No files trashed from current dir ('%s')" % os.path.realpath(os.curdir)else :     index=raw_input("What file to restore [0..%d]: " % (len(trashed_files)-1))     if index == "*" :         for tfile in trashed_files :             try:                 tfile.restore()             except IOError, e:                 import sys                print >> sys.stderr, str(e)                 sys.exit(1)     elif index == "" :         print "Exiting"     else :         index = int(index)         try:             trashed_files[index].restore()         except IOError, e:             import sys            print >> sys.stderr, str(e)             sys.exit(1)我正進入(狀態:        elif index == "" :         ^     IndentationError: expected an indented block
查看完整描述

3 回答

?
繁星淼淼

TA貢獻1775條經驗 獲得超11個贊

如錯誤消息所示,您有縮進錯誤。它可能是由制表符和空格混合引起的。


查看完整回答
反對 回復 2019-09-26
?
守著一只汪

TA貢獻1872條經驗 獲得超4個贊

我遇到了同樣的問題,并(通過對類似問題的回答)發現問題是我沒有正確縮進文檔字符串。不幸的是,IDLE在這里沒有提供有用的反饋,但是一旦我修復了文檔字符串縮進,問題就消失了。

特別是---產生縮進錯誤的錯誤代碼:

def my_function(args):"Here is my docstring"
    ....

避免縮進錯誤的好代碼:

def my_function(args):
    "Here is my docstring"
    ....

注意:我并不是說這問題所在,但可能是,因為就我而言,這是問題所在!


查看完整回答
反對 回復 2019-09-26
  • 3 回答
  • 0 關注
  • 1652 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號