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:

  1. '_init_' != '__init__';
  2. where years defined?
  3. given self.name string, think "total employees %d" % self.name do?
  4. displaycount recursively calls on new mylist 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

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -