Python no output from class method -
when call displaycount
method of list subclass, no output. 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()
you have few problems:
'_init_' != '__init__'
;- where
years
defined? - given
self.name
string, think"total employees %d" % self.name
do? displaycount
recursively calls on newmylist
instance.
perhaps 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()
Comments
Post a Comment