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

Discussion in 'Python' started by Peter Otten, Mar 2, 2013.

  1. Peter Otten

    Peter Otten Guest

    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.
     
    Peter Otten, Mar 2, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Zhou Fan
    Replies:
    4
    Views:
    329
    Alf P. Steinbach
    Mar 23, 2006
  2. jonnytheclown

    Correct way to inherit from 3rd party class

    jonnytheclown, Feb 21, 2005, in forum: Perl Misc
    Replies:
    6
    Views:
    142
    Peter Scott
    Feb 22, 2005
  3. Ian Kelly
    Replies:
    0
    Views:
    116
    Ian Kelly
    Mar 2, 2013
  4. Ian Kelly
    Replies:
    0
    Views:
    117
    Ian Kelly
    Mar 2, 2013
  5. Rick Johnson
    Replies:
    3
    Views:
    115
    Jason Swails
    Mar 3, 2013
Loading...

Share This Page