Could you please help me to find the problem? Python code that works:
class ParamWindow:
def __init__(self, b):
self.a = b
print self.a
params = ParamWindow(8)
print params.a
this prints 8 and 8. Ok. Then I do:
class ParamWindow:
def __init__(self, parent, b):
self = wx.Frame(parent = parent, id=-1, title="Parameters")
self.a = b
print self.a
params = ParamWindow(None, 8)
print params.a
and it says “ParamWindow instance has no attribute ‘a'”. Why has not it? I told him that self is Frame and then added a field “a” (no error at this point) but when i ask to print it (error at print line), it forgets that “a” exists…
Where am I wrong?
Thanks.
Here you reassign
self, so you end up having no reference to theParamWindowinstance any more! You should never do that! What are you trying to achieve?Here, you assign
atoself, which is now theFrame, not theParamWindow.ParamWindow.anever gets defined and you get the error later on.Maybe you want to inherit from
Frame? If so, your code should look like this: