Python No Output From Class Method
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)
Solution 1:
You have a few problems:
'_init_' != '__init__'
;- Where is
years
defined? - Given that
self.name
is a string, what do you think"total employees %d" % self.name
will do? displaycount
currently recursively calls itself on a newmylist
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()
Post a Comment for "Python No Output From Class Method"