How can I fix the error on this Python code?
Question: I have this superclass:

import wx

    
    
    class Plugin(wx.Panel):
        def __init__(self, parent, *args, **kwargs):
            wx.Panel.__init__(self, parent, *args, **kwargs)
            self.colorOver = ((89,89,89))
            self.colorLeave = ((110,110,110))
            self.SetBackgroundColour(self.colorLeave)
            self.SetForegroundColour(self.colorLeave)
            self.name = "plugin"
    
            wx.StaticText(self, -1, self.getName(), style=wx.ALIGN_LEFT)
    
    
            self.Bind(wx.EVT_ENTER_WINDOW, self.onMouseOver)
            self.Bind(wx.EVT_LEAVE_WINDOW, self.onMouseLeave)
    
        def onMouseOver(self, event):
            self.SetBackgroundColour(self.colorOver)
            self.Refresh()
    
        def onMouseLeave(self, event):
            self.SetBackgroundColour(self.colorLeave)
            self.Refresh()
    
        def OnClose(self, event):
            self.Close()
            app.Destroy()
    
        def getName(self):
            return self.name
    

and this subclass:

    
    
    import plugin
    import wx
    
    class noisePlugin(plugin.Plugin):
        self.name = "noise"
    

and it gives me this error compiling the subclass:

    
    
    Traceback (most recent call last):
      File "C:\Users\André Ferreira\Desktop\Tese\Código Python\SoundLog\Plugins\noisePlugin.py", line 4, in <module>
        class noisePlugin(plugin.Plugin):
      File "C:\Users\André Ferreira\Desktop\Tese\Código Python\SoundLog\Plugins\noisePlugin.py", line 5, in noisePlugin
        self.name = "noise"
    NameError: name 'self' is not defined
    

What can I do to fix this error? I want getName() method to return the name of
the instanciated class!

Thanks in advance :)


Answer: Make the subclass

    
    
    class noisePlugin(plugin.Plugin):
        def __init__(self, *a, **k):
            plugin.Plugin.__init__(self, *a, **k)
            self.name = "noise"
    

Whenever you want to use `self.`something you have to be **within a method** ,
not at class level outside of methods!

