Python Forum

Full Version: AttributeError: type object 'MyClass' has no attribute 'channel'
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all
I have a trouble with getting the list of self.channel when I am trying to get the list of strings from my another script called test.py. In player.py when I have input import test, I am getting an error: AttributeError: type object 'MyClass' has no attribute 'channel' when I try to run the scripts.

The error are highlight on this line:

    self.channel = test.MyClass.channel()
in test.py it show:

    from player import MyPlayer
    
    class MyClass(xbmcgui.WindowXML):

    def __init__(self, *args, **kwargs):
        self.channel = list()
in player.py:

    import test
    
    class MyPlayer(xbmcgui.WindowXML):
      def __init__(self, *args, **kwargs):
          self.channel = test.MyClass.channel()
I want to get access to the self.channel from test.py to get the list of strings. Can you please show me how I could get access to the self.channel from the test.py script to get the list of strings??
The channel attribute is an instance attribute, it is only create in __init__ when you create an instance of the class. You are trying to reference it from the class itself. You need to create an instance, or make it a class attribute.
(Sep-29-2017, 04:11 PM)ichabod801 Wrote: [ -> ]The channel attribute is an instance attribute, it is only create in __init__ when you create an instance of the class. You are trying to reference it from the class itself. You need to create an instance, or make it a class attribute.

Oh thank you for your advice. From what you said I have try to defined the self.player = None in __init__ and add the self.player = self.parent.channel in init(self):` so I have got it working!!! :)