Python Forum
AttributeError: type object 'MyClass' has no attribute 'channel'
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AttributeError: type object 'MyClass' has no attribute 'channel'
#1
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??
Reply
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
(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!!! :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  getpass.getpass() results in AttributeError: module 'os' has no attribute 'O_NOCTTY' EarthAndMoon 4 719 Oct-03-2023, 02:00 PM
Last Post: deanhystad
  AttributeError: '_tkinter.tkapp' object has no attribute 'username' Konstantin23 4 1,532 Aug-04-2023, 12:41 PM
Last Post: Konstantin23
  Python: Regex is not good for re.search (AttributeError: 'NoneType' object has no att Melcu54 9 1,385 Jun-28-2023, 11:13 AM
Last Post: Melcu54
  Parallel processing - AttributeError: Can't get attribute 'sktimekmeans' Mohana1983 1 704 Jun-22-2023, 02:33 AM
Last Post: woooee
  Python: AttributeError: 'PageObject' object has no attribute 'extract_images' Melcu54 2 3,667 Jun-18-2023, 07:47 PM
Last Post: Melcu54
  Object attribute behavior different in 2 scripts db042190 1 686 Jun-14-2023, 12:37 PM
Last Post: deanhystad
  cx_oracle Error - AttributeError: 'function' object has no attribute 'cursor' birajdarmm 1 2,215 Apr-15-2023, 05:17 PM
Last Post: deanhystad
  Pandas AttributeError: 'DataFrame' object has no attribute 'concat' Sameer33 5 5,301 Feb-17-2023, 06:01 PM
Last Post: Sameer33
  declaring object parameters with type JonWayn 2 857 Dec-13-2022, 07:46 PM
Last Post: JonWayn
  how to check if someone send a message in a discord channel? Zerolysimin 1 742 Nov-06-2022, 11:10 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020