Mar-14-2024, 03:41 PM
Dear community,
I'm trying to append str to a list, which is in a dataclass.
I'm totally new to dataclasses.
I used to use a textfile for storing strings.
Then I read about dataclasses for storing data.
What is the simplest way for appending string to a list in a dataclass?
When I try mylist: list = []
then it is said to use default_factory...
Thanks a lot for the help, I did a lot of googling, but with no success...
I'm trying to append str to a list, which is in a dataclass.
I'm totally new to dataclasses.
I used to use a textfile for storing strings.
Then I read about dataclasses for storing data.
What is the simplest way for appending string to a list in a dataclass?
When I try mylist: list = []
then it is said to use default_factory...
@dataclass class C(): mylist: list a: str def __post_init__(self): return self.mylist.append(self.a) c = C("a") print(c.mylist) c = C("b") print(c.mylist)mylist should be ["a", "b"].
Thanks a lot for the help, I did a lot of googling, but with no success...