Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #40339

Re: Is it correct this way to inherit from a list?

From Peter Otten <__peter__@web.de>
Subject Re: Is it correct this way to inherit from a list?
Date 2013-03-02 18:19 +0100
Organization None
References <kgtbb9$3ps$1@tdi.cu.mi.it>
Newsgroups comp.lang.python
Message-ID <mailman.2779.1362244783.2939.python-list@python.org> (permalink)

Show all headers | View raw


gialloporpora wrote:

> I would like to inherit from the list native class.
> really I expected that was possible to use native list method without
> redefining them, for example the __repr__ method.
> 
> I don't know if i have made something wrong, this is my code (I obmit
> customized methods that I have added):
> 
> from os.path import exists
> 
> class vector(list):

> def __getitem__(self, key):
>     return self._list[key]

[and many more]

> Is it correct or it exists another way to inherit from list class?

Have you considered subclassing collections.MutableSequence instead?
You cannot instantiate that class until you have overridden all its abstract 
methods.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Is it correct this way to inherit from a list? gialloporpora <gialloporpora@gmail.com> - 2013-03-02 18:02 +0100
  Re: Is it correct this way to inherit from a list? Peter Otten <__peter__@web.de> - 2013-03-02 18:19 +0100
  Re: Is it correct this way to inherit from a list? Ian Kelly <ian.g.kelly@gmail.com> - 2013-03-02 10:22 -0700
  Re: Is it correct this way to inherit from a list? Ian Kelly <ian.g.kelly@gmail.com> - 2013-03-02 10:26 -0700
    Re: Is it correct this way to inherit from a list? gialloporpora <gialloporpora@gmail.com> - 2013-03-03 03:33 +0100
  Re: Is it correct this way to inherit from a list? Rick Johnson <rantingrickjohnson@gmail.com> - 2013-03-02 09:46 -0800
    Re: Is it correct this way to inherit from a list? gialloporpora <gialloporpora@gmail.com> - 2013-03-03 03:30 +0100
      Re: Is it correct this way to inherit from a list? Chris Angelico <rosuav@gmail.com> - 2013-03-03 14:18 +1100
      Re: Is it correct this way to inherit from a list? "Colin J. Williams" <cjw@ncf.ca> - 2013-03-03 09:21 -0500
        Re: Is it correct this way to inherit from a list? Jason Swails <jason.swails@gmail.com> - 2013-03-03 15:40 -0500

csiph-web