[英]Class Name is not defined error in python
在我進行 python 編程時遇到了一個錯誤。 代碼如下。
import skfuzzy as fuzz
from skfuzzy import control as ctrl
f =fuzzy_()
print(f)
class fuzzy_:
def __init__(self):
pass
def values(self,t = None, m = None, p = None):
“class 名稱模糊_未定義”。 顯示錯誤。
請幫忙。
您需要像這樣重新排序:
import skfuzzy as fuzz
from skfuzzy import control as ctrl
class fuzzy_:
def __init__(self):
pass
def values(self,t = None, m = None, p = None):
# First define the class
# Then instantiate it
f = fuzzy_()
print(f)
python 解釋器需要先找到 class 定義,同時從上到下讀取代碼。 在您的代碼示例中,解釋器嘗試實例化fuzzy_
_class object,但在此之前它不知道fuzzy_()
是什么而引發錯誤。
python interpreter reads from top to bottom, you are calling the instance of class before defining the class, move line 3 and 4 to the bottom after declaring the class and it should be fine.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.