Dataclasses create init and call post_init
__init__
is implemented and that's how the attributes are initialized__post_init__
is called after__init__
to allow for further initializations
from dataclasses import dataclass
@dataclass
class Point():
x : float
y : float
name : str
def __post_init__(self):
print(f"In post init: {self.name}")
from shapes import Point
p1 = Point(2, 3, 'left')