Inheriting from Python list object(type?)

Lyosha lyoshaM at gmail.com
Wed May 23 15:24:21 EDT 2007


On May 23, 12:19 pm, Lyosha <lyos... at gmail.com> wrote:
> On May 23, 12:07 pm, Mangabasi <mangab... at gmail.com> wrote:
>
> > On May 23, 1:43 pm, "Jerry Hill" <malaclyp... at gmail.com> wrote:
>
> > > On 23 May 2007 11:31:56 -0700, Mangabasi <mangab... at gmail.com> wrote:
>
> > > > When I modified this to:
>
> > > > class Point(list):
> > > >     def __init__(self,x,y):
> > > >         super(Point, self).__init__([x, y])
> > > >         self.x = x
> > > >         self.y = y
>
> > > > It worked.
>
> > > Are you sure?
>
> > > >>> p = Point(10, 20)
> > > >>> p
> > > [10, 20]
> > > >>> p.x
> > > 10
> > > >>> p.x = 15
> > > >>> p
> > > [10, 20]
> > > >>> p[0]
> > > 10
> > > >>> p.x
> > > 15
>
> > > That doesn't look like what you were asking for in the original post.
> > > I'm afraid I don't know anything about numpy arrays or what special
> > > attributes an object may need to be put into a numpy array though.
>
> > > --
> > > Jerry
>
> > This is the winner:
>
> > class Point(list):
> >     def __init__(self, x, y, z = 1):
> >         super(Point, self).__init__([x, y, z])
> >         self.x = x
> >         self.y = y
> >         self.z = z
>
> [...]
>
> http://docs.python.org/dev/whatsnew/node3.htmlannounces named tuples
> in python2.6.  This is not what you want since tuples are immutable,
> but you might get some inspiration from their implementation.  Or
> maybe not.


Dude, google groups suck!  They say "an error has occurred" and the
message is happily posted.




More information about the Python-list mailing list