[英]SyntaxError: expected an indented block when using if and elif with empty blocks
[英]"expected an indented block" when using except: continue
運行以下代碼時:
for line in file:
try:
result = dataclass.from_json(line)
except Error as error:
# ignore records for non-matches
continue
我收到了
“需要一個縮進的塊”
try - except
語句的正確形狀是:
for line in [1,2,3]:
try:
result = 0
except ValueError:
# ignore records for non-matches
continue
語句continue
(大致意思是“什么都不做”)位於except
塊內,因此您需要一個標識。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.