Title: Objects in List

Hi

I'm new to python (have a java background).  I'm trying to add object to a list, and afterwards manipulate the object again.  How do a cast a object to another object

My Code:

class MyObject:       
        """A simple VO class"""
        def setName(self, newName):
                self.name=newName
               
        def getName(self):
                return self.name

def main():
        list=[]
        #created object in container
        for i in range(10):
                myObject = MyObject()          
                name = 'name:' + str(i)
                myObject.setName(name)
                list.append(myObject)
       
    #manipulate object in list
        for p in enumerate(range(10)):
                myObject=p
                print myObject.getName()

               
if __name__ == '__main__':
        main()

The ERROR:

C:\development\python__>python list.py
Traceback (most recent call last):
  File "list.py", line 25, in ?
    main()
  File "list.py", line 21, in main
    print myObject.getName()
AttributeError: 'tuple' object has no attribute 'getName'
   

_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to