deriving from array.array

Torsten Mohr tmohr at s.netic.de
Tue Jan 26 12:41:44 EST 2010


Hello,

i try to derive a class from array.array:


import array

class Abc(array.array):
    def __init__(self, a, b):
        array.array.__init__(self, 'B')
        self.a = a
        self.b = b


a = Abc(4, 5)
print a
print a.a


I get an error for "a = Abc(4, 5)", seems the parameters are
forwarded to array's __init__ as they are.  Though i explicitly
call __init__() for array.

I'd like to use array and make sure it's type is always 'B'.
I'd like to derive because i don't want to rewrite all the methods like 
__getiem__ for my class and then call array's __getitem__.

How do i best derive from array.array?


Thanks for any hints,
Torsten.




More information about the Python-list mailing list