class lista(object):
listanumere=[]
def printer(self):
print self.listanumere
def adds(self,numar):
self.listanumere.append(numar)
class movies():
def __init__(self,ide,nume):
self.__nume=nume
self.__ide=ide
listarez=lista
a=movies(1,"David")
lista.adds(a)
lista.printer()
Error:
TypeError: unbound method adds() must be called with lista instance as first argument (got movies instance instead)
So my question is: How to make a class which contains a list of elements defined in another class, for example a class which contains the list of movies and some methods which modify the list for example add a new movie or remove a movie with a certain ID?
__init__method, it's unclear what the intent is there, you have several statements on the same line without indentation.listaclass to do that a plain old list doesn't already do?