[Python-Dev] Dictionary subclasses and exec
Fred L. Drake, Jr.
fdrake@acm.org
Tue, 23 Oct 2001 21:30:27 -0400
akuchlin@mems-exchange.org writes:
> Oh, well; I need to come up with a different example for subclassing a
> built-in type, then. Thanks! <puts on thinking cap>
Andrew,
You can take a look at that implementation of
xml.dom.minidom.NodeList; for Python 2.2, the implementation goes like
this:
----------------------------------------------------------------------
class NodeList(list):
def item(self, index):
if 0 <= index < len(self):
return self[index]
length = property(lambda self: len(self),
doc="The number of nodes in the NodeList.")
----------------------------------------------------------------------
-Fred
--
Fred L. Drake, Jr. <fdrake at acm.org>
PythonLabs at Zope Corporation