I always want to shorten my code, for those classes have lots of variables, writing init
method is time consuming.
There are few solutions for it to automatically initialize instance variables. Automatically initialize instance variables?
Since Python 3.7+, there is one more solution is to use dataclass
, but since Python have shared variables during instances How to avoid having class data shared among instances?
So using dataclass to do automatic attribute assignment can be considered as good practice or it's only suitable for data-classes only?