Looking for a list subclassing example...

Shagshag13 shagshag13 at yahoo.fr
Tue Jun 4 12:42:04 CEST 2002


i do it like that, it work, but don't know if it's correct :

class Shag(list):
 def __init__(self, emptyValue = None):
  self._emptyValue = emptyValue

 def reset(self):
  del self
  self = []

 def __setitem__(self, key, item):
  try:
   list.__setitem__(self, key, item)
  except IndexError:
   for i in range(len(self), key):
    self.append(self._emptyValue)
   self.append(item)





More information about the Python-list mailing list