Created
October 19, 2022 12:19
-
-
Save 1pha/672d52a9ff58efb939d8ec1b1973f005 to your computer and use it in GitHub Desktop.
Dataclass and Attributes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Explanations will further be attached. | |
from dataclasses import dataclass, field | |
@dataclass | |
class A: | |
d: int = 3 | |
_e: int = 5 | |
_g: list = field(default_factory=list) | |
def __post_init__(self): | |
self._f = 6 | |
@property | |
def e(self): | |
return self._e | |
@property | |
def f(self): | |
return self._f | |
@property | |
def g(self): | |
return self._g | |
def flush(self): | |
self.__dict__ = {"d": self.d} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment