Why no list heritable type?

James Stroud jstroud at mbi.ucla.edu
Thu Dec 16 15:53:32 EST 2004


The thread "why not arrays" got me thinking. I would really like to inherit 
from a list so that I can add methods based on its contents, say if I filled 
it with a type of object and wanted to iterate over all objects. I have built 
a wrapper around a list like this for general use:

class list_of_objects:
  def __init__(self):
    self.data = []
  def __len__(self):
    return len(self.data)
  etc ...

Then it can be heritable and I can add or override methods. Why aren't built 
in lists and dictionaries real heritable types that can save this kind of 
patchwork? Is there a pythonic reason I am missing here?

James


-- 
James Stroud, Ph.D.
UCLA-DOE Institute for Genomics and Proteomics
611 Charles E. Young Dr. S.
MBI 205, UCLA 951570
Los Angeles CA 90095-1570
http://www.jamesstroud.com/



More information about the Python-list mailing list