python object AttributeError: type object 'Track' has no attribute 'title'

Posted by ccwhite1 on Stack Overflow See other posts from Stack Overflow or by ccwhite1
Published on 2011-02-22T14:39:06Z Indexed on 2011/02/22 15:25 UTC
Read the original article Hit count: 352

Filed under:
|
|

I apologize if this is a noob question, but I can't seem to figure this one out.

I have defined an object that defines a music track (NOTE: originally had the just ATTRIBUTE vs self.ATTRIBUTE. I edited those values in to help remove confusion. They had no affect on the problem)

class Track(object):
  def __init__(self, title, artist, album, source, dest):
    """
    Model of the Track Object

    Contains the followign attributes:
    'Title', 'Artist', 'Album', 'Source', 'Dest'
    """
    self.atrTitle = title
    self.atrArtist = artist
    self.atrAlbum = album
    self.atrSource = source
    self.atrDest = dest

I use ObjectListView to create a list of tracks in a specific directory

....other code....
self.aTrack = [Track(sTitle,sArtist,sAlbum,sSource, sDestDir)]
self.TrackOlv.AddObjects(self.aTrack)
....other code....

Now I want to iterate the list and print out a single value of each item

list = self.TrackOlv.GetObjects()

for item in list:
    print item.atrTitle

This fails with the error

AttributeError: type object 'Track' has no attribute 'atrTitle'

What really confuses me is if I highlight a single item in the Object List View display and use the following code, it will correctly print out the single value for the highlighted item

list = self.TrackOlv.GetSelectedObject()
print list.atrTitle

© Stack Overflow or respective owner

Related posts about python

Related posts about wxpython