T
TG
Hi there.
I'm trying to create a simple class called Vector which inherit from
array.
class Vector(array):
def __init__(self,length):
"""initialize a vector of random floats of size length. floats
are in interval [0;1]"""
array.__init__(self,'f')
for _ in xrange(length):
self.apprend(random())
but then :TypeError: array() argument 1 must be char, not int
Well, I guess it means array's __init__ method is not called with
proper arguments ... It seems there is a problem with __init__
overloading, like when I call Vector(x), it directly calls __init__
method from array rather than the one defined in Vector class. Anyone
got an idea on this ?
I'm trying to create a simple class called Vector which inherit from
array.
class Vector(array):
def __init__(self,length):
"""initialize a vector of random floats of size length. floats
are in interval [0;1]"""
array.__init__(self,'f')
for _ in xrange(length):
self.apprend(random())
but then :TypeError: array() argument 1 must be char, not int
Well, I guess it means array's __init__ method is not called with
proper arguments ... It seems there is a problem with __init__
overloading, like when I call Vector(x), it directly calls __init__
method from array rather than the one defined in Vector class. Anyone
got an idea on this ?