When I run the code below:
import pandas as pd
from dataclasses import dataclass
@dataclass
class SomeClass:
df_in: pd.DataFrame
def __post__init__(self):
self.b = 1
if __name__ == '__main__':
df_in = pd.DataFrame([])
p = SomeClass(df_in=df_in)
p.b
I get
AttributeError: 'SomeClass' object has no attribute 'b'
Why?
EDIT:
Am I using post__init correctly as there is no init in dataclasses
Your __post_init__
function is misnamed. You should only have one underscore between post and init, but you have two.