I define a class as below:
import numpy as np
class Vector:
def __init__(self, v):
self.v = v
I can create an instance of the class by doing the following:
p1 = np.array([0.0, 0.0, 0.0])
v1 = Vector(p1)
v2 = Vector(3)
My intention is that Vector always contains a vector in the 3D space. But, what is the proper way in python to make sure Vector will always be a 3-component vector?
__init__and raise aValueErrorif you received a bad value.