Forums

AttributeError: 'MyClass' object has no attribute

Hi guys

I need a bit of your help. I've created the variables that I want to store a list of arrays outside the for loop. I have got a problem with the code that I currently using.

When I try this:

import xbmc
import xbmcgui
import xbmcaddon

class ProgramControls(object):
     def __init__(self, control, program):
         self.control = control
         self.program = program

class MyClass(xbmcgui.WindowXML):

     def __init__(self):
         self.program_buttons = list()
         self.button_focus = 'programs_yellow.png'
         self.button_nofocus = 'channels_bar1.png'

 program_controls = xbmcgui.ControlButton(
        int(position_start), 
        int(position_top), 
        int(program_width), 
        int(program_height), 
        program_title, 
        focusTexture = path + self.button_focus, 
        noFocusTexture = path + self.button_nofocus,
        textColor ='0xFFFFFFFF',
        focusedColor ='0xFF000000'
    )
    self.program_buttons.append(ProgramControls(program_controls, program))
programs_button = [elem.control for elem in self.program_buttons]
program_id = list()
program_width = list()

for elem in programs_button:
    program_id = elem.getId()
print program_id
self.addcontrols(programs_button)

It will give me the error: AttributeError: 'MyClass' object has no attribute 'programs_button'

The error are jumping on this line:

for elem in self.programs_button:

Can you please help me how I can fix this?

Hi Chris,

I might be missing something, but I can't see the precise line you mention in the code snippet. The essence of the error, however, is that you're accessing the programs_button attribute prior to it being set on the MyClass object.

If your class definition above is accurate then this is a little puzzling since it's initialised in __init__(). Is this attribute something to do with the base class? I do notice you're not chaining into xbmcgui.WindowXML.__init__() anywhere in your __init__() - remember Python doesn't call base class initialisers automatically. However, it doesn't seem too likely that this is the issue to me, but it may be a problem you may need to look at nonetheless.

I'm also having difficulty telling where program_controls is scoped - my iPhone browser may be confusing things, but it looks like it's indented by one character relative to the class MyClass line - this seems like a syntax error (since it doesn't match any previous indent level) but perhaps this is a cut and paste error?

Hi chris0147, I see there's a bunch of XBMC libraries in your code sample -- are you hosting some sort of XBMC app on PythonAnywhere? If so, cool! Tell us more about it! I've been playing with raspbmc at home, am curious to know more...

If you're after generic, non-pythonanywhere-related help, you might find codementor will be more help than we can be (although Cartroo is seldom wrong about anything...)

EDIT: Bah, I'm blind. I just spotted that the missing attribute is programs_buttons whereas the code sets program_buttons. Looks like a typo.

ORIGINAL: Ah if only that were true, Harry! (^_^)

In this particular case, though, it does seem an odd error given the code snippet, which makes me suspicious that I'm missing something. I did confirm that snippet is syntactically invalid as stated, however, for the reason I suspected:

IndentationError: unindent does not match any outer indentation level

Probably just a cut and paste error, but sometimes these minor issues can be relevant.

hey Cartroo, yes of course I'm accessing to programs_button to get a list of arrays.

I have changed from this:

for elem in self.program_buttons:

To this:

for elem in programs_button:

Now it works :)

@harry No I don't have any app to store on pythonanywhere so why do you asked me for? I'm making my own tv guide addon with the list of channels and programs that are including with live streams :)

I'm asking because, strictly speaking, this forum is meant for PythonAnywhere users to discuss technical issues relating to PythonAnywhere, so it may not be the best place for posts that have nothing to do with this platform...

How did you end up here? I think you're not the first XBMC hacker to have shown up asking questions here -- are we referenced on a messsage board somewhere? or do we come up on a particular google search?