title: How to inherit and extend a list object in Python?
body: <p>I am interested in using the python list object, but with slightly altered functionality. In particular, I would like the list to be 1-indexed instead of 0-indexed. E.g.:</p>
  
  <pre><code>&gt;&gt; mylist = MyList()
  &gt;&gt; mylist.extend([1,2,3,4,5])
  &gt;&gt; print mylist[1]
  </code></pre>
  
  <p>output should be: 1</p>
  
  <p>But when I changed the <code>__getitem__()</code> and <code>__setitem__()</code> methods to do this, I was getting a <code>RuntimeError: maximum recursion depth exceeded</code> error. I tinkered around with these methods a lot but this is basically what I had in there:</p>
  
  <pre><code>class MyList(list):
      def __getitem__(self, key):
          return self[key-1]
      def __setitem__(self, key, item):
          self[key-1] = item
  </code></pre>
  
  <p>I guess the problem is that <code>self[key-1]</code> is itself calling the same method it's defining. If so, how do I make it use the <code>list()</code> method instead of the <code>MyList()</code> method? I tried using <code>super[key-1]</code> instead of <code>self[key-1]</code> but that resulted in the complaint <code>TypeError: 'type' object is unsubscriptable</code></p>
  
  <p>Any ideas? Also if you could point me at a good tutorial for this that'd be great!</p>
  
  <p>Thanks!</p>