Inherit from array
Sion Arrowsmith
siona at chiark.greenend.org.uk
Wed Apr 26 11:06:43 EDT 2006
TG <girodt at gmail.com> wrote [something like]:
>from array import array
>class Vector(array):
> def __init__(self,size):
> array.__init__('f')
>
>v = Vector('c')
>print repr(v)
>
>will output :
>
>array('c')
Is this a case of new-sytle classes being confusing? Because
I'm certainly confused. I guess what's needed is:
class Vector(array):
def __new__(cls, size):
self = array.__new__(array, 'f')
...
return self
But how does one determine what classes need to have __init__
overridden and which __new__ when subclassing?
--
\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