list - len() function not working properly in Python -


i have following code:

class stat(list):     def __init__(self, lst = []):         self.s = list(lst)      def __repr__(self):         return "stat({})".format(self.s)      def add(self, item):         self.s.append(item)      def len(self):                return len(self.s)  ...(more methods, not necessary) 

all of methods work len(). no matter length of stat object, returned length 0; don't understand why.

it return 0 when using this:

x = stat([1,3,4,5]) print len(x) 

if want override len function use code:

def __len__(self):            return len(self.s) 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -