[英]Pycharm - Disable 'Local variable 'xxx' might be referenced before assignment'
[英]PyCharm: Variable in finally block might be referenced before assignment?
也許PyCharm在看到分配時沒有考慮“分配給什么”。 就是說, None
是什么與眾不同,請考慮是否改寫了以下內容:
try:
category = lst[2]
except:
category = Noone
finally:
if not category:
category = self.default_category
(或None/1
等),然后您將得到:
NameError: name 'category' is not defined
如果lst
為空,則在異常中會有一個異常:
當try子句中發生了異常且未由except子句處理(或在except或else子句中發生)時,將在執行finally子句后重新引發該異常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.