Skip to content

Instantly share code, notes, and snippets.

@1pha
Created October 19, 2022 12:19
Show Gist options
  • Save 1pha/672d52a9ff58efb939d8ec1b1973f005 to your computer and use it in GitHub Desktop.
Save 1pha/672d52a9ff58efb939d8ec1b1973f005 to your computer and use it in GitHub Desktop.
Dataclass and Attributes
# 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