我正在嘗試獲取WxPython復選框的值。當我在類中運行以下命令時:print(self)a = dir(self)print(a)#result<__main__.Window object at 0x03B02670>['AcceleratorTable', 'AcceptsFocus', etc... 'm_staticText3', 'm_staticText31', 'm_staticText311', 'm_staticText3111', 'm_staticText3112', 'm_staticText31121', 'm_staticline1', 'm_staticline3']我的復選框是返回結果的一部分。但是,當我用“self”代替類“Window”時,復選框屬性丟失了!print(Window)a = dir(Window)print(a)#result<class '__main__.Window'>['AcceleratorTable', 'AcceptsFocus', etc.., 'WindowVariant', '__bool__', '__class__', '__del__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__nonzero__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__']它看起來是一樣的,但我的復選框沒有被返回!這是怎么回事?
1 回答

料青山看我應如是
TA貢獻1772條經驗 獲得超8個贊
此類類未實例化。因此,它無法訪問任何需要類實例的內容。在下面的代碼中:Window
class A:
b = 0
def __init__(self):
self.a = 1
print(dir(A))
inst = A()
print(dir(inst))
dir(A)將不包含 ,因為 訪問 需要實例化,因為它是為方法中的每個實例單獨聲明的。它將包含 ,這是靜態的(屬于類本身,而不是它的實例)。 將同時包含 和 。aa__init__bdir(inst)ab
添加回答
舉報
0/150
提交
取消