Make Dog a dataclass and create three dogs
This commit is contained in:
13
heaven.py
13
heaven.py
@@ -1,6 +1,19 @@
|
|||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
class Dog:
|
class Dog:
|
||||||
|
name: str
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
global heaven
|
global heaven
|
||||||
heaven.append(self)
|
heaven.append(self)
|
||||||
|
|
||||||
|
|
||||||
heaven = []
|
heaven = []
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
Dog("Fido")
|
||||||
|
Dog("Rex")
|
||||||
|
Dog("Spot")
|
||||||
|
print(heaven)
|
||||||
|
Reference in New Issue
Block a user