Subclassing array

Sion Arrowsmith siona at chiark.greenend.org.uk
Thu May 4 17:27:42 CEST 2006


Alex Martelli <aleaxit at yahoo.com> wrote:
>TG <girodt at gmail.com> wrote:
>> When I call Vector.__init__() in Stimulus, doesn't it also call __new__
>> ? I don't understand the detail of callings to __new__ and __init__ in
>> python inheritance ...
>Calling a (new-style) class does __new__ first, THEN calls the class's
>__init__ on the resulting instance -- and the arguments you're passing
>when calling the class go to both __new__ and __init__.

... so you might want something like:

class Vector(array):
    def __new__(cls,*args):
        return super(Vector,cls).__new__(cls,'f')

-- 
\S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |    -- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump



More information about the Python-list mailing list