A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2001-October/018107.html below:

[Python-Dev] Dictionary subclasses and exec

[Python-Dev] Dictionary subclasses and exec [Python-Dev] Dictionary subclasses and execFred 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




RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4