I have a below NormalClass
that I want to structure as a dataclass
. However I was not sure how I can pass the date_str
param without __init__
in the dataclass
. Any thoughts?
class FieldDateTime():
def __init__(self, data, d_format='%m/%d/%y %I:%M %p'):
try:
self.data = datetime.strptime(data, d_format)
except ValueError as e:
raise ValueError('Dateformat incorrect')
def __call__(self):
return self.data
class NormalClass:
def __init__(self, id, date_str):
self.id: int = id
self.dt: FieldDateTime = FieldDateTime(date_str)
@dataclass
class DataClassObj:
id: int
dt: FieldDateTime(date_str)
How do I pass the date_str as an argument in the data class representation (DataClassObj) without the init?