Reputation: 1
When I call the displaycount
method of my list subclass, I get no output. What is the problem?
class mylist(list):
def _init_(self,name,age):
list._init_(self, years)
self.name = name;
self.age = age;
def displaycount(self):
print "total employees %d" % self.name
emp1 = mylist('lada', 20)
emp1.displaycount()
Upvotes: 0
Views: 824
Reputation: 121955
You have a few problems:
'_init_' != '__init__'
;years
defined?self.name
is a string, what do you think "total employees %d" % self.name
will do?displaycount
currently recursively calls itself on a new mylist
instance.Perhaps you mean:
class mylist(list):
def __init__(self, name, age):
super(mylist, self).__init__()
self.name = name
self.age = age
def displaycount(self):
print "total employees {0}".format(self.age)
emp1 = mylist('lada', 20)
emp1.displaycount()
Upvotes: 3