我正在嘗試爲課程做我的項目,並在嘗試運行時不斷收到此錯誤。unindent不匹配任何外部縮進級別。這是我的老師給我的代碼
try:
^ IndentationError: unindent does not match any outer indentation level
這裏是我的代碼:
author=''
try:
fh = open(sys.argv[0], encoding="utf8")
for line in fh:
m = re.search('# *AUTHOR: *([\w\-]+ *[\w\-]+)', line)
if m is not None:
author = m.group(1)
except(IOError, OSError) as err:
print(err)
return ''
finally:
if fh is not None:
fh.close()
return author.lower()
嘛,應該有至少一個以上線..沒有什麼最後的'後:',意思是蟒蛇預計後'ERR更多:'.. – MatsLindh
如果你不想在'except'塊中做任何事情,它需要包含'pass' – Barmar
還存在縮進錯誤嗎?因爲它看起來像你已經編輯你的代碼來糾正該錯誤 – Mangohero1