I have a triangle class with vertices, area, and contours. What is the Pythonic way of setting multiple members in a constructor using One method, if needing to set three members in a Constructor at once?
I'm using dictionary method below, however it seems clunky. Wondering if this is appropriate or any optimal method?
This question is a variation of this question, What is a clean, Pythonic way to have multiple constructors in Python?
class TriangleData():
vertices_key: str = 'vertices'
triangle_area_key: str = 'triangle_area'
contours_key: str = 'contours'
def __init__(self, contour_data: np.ndarray):
self.contour_data = contour_data
data = self.get_triangle_data()
self.vertices: np.ndarray = data[self.vertices_key]
self.triangle_area: float = data[self.triangle_area_key]
self.poly_dp_contours: np.ndarray = data[self.contours_key]
self.color = self.get_color()
def get_triangle_data(self):
# Run calculations from original contour dataetc etc
.....
return {
self.vertices_key: vertices_final,
self.triangle_area_key: triangle_area,
self.contours_key: contours
}