generated from dopt-python/py311
track prototypes
This commit is contained in:
28
prototypes/tests.py
Normal file
28
prototypes/tests.py
Normal file
@@ -0,0 +1,28 @@
|
||||
# %%
|
||||
import dataclasses as dc
|
||||
|
||||
|
||||
# %%
|
||||
@dc.dataclass(slots=True)
|
||||
class Address:
|
||||
street: str
|
||||
number: int
|
||||
postal_code: str
|
||||
city: str
|
||||
|
||||
def export(self):
|
||||
data = {}
|
||||
for f in dc.fields(self):
|
||||
val = getattr(self, f.name)
|
||||
if f.type is int:
|
||||
val = str(val)
|
||||
data[f.name] = val
|
||||
|
||||
return data
|
||||
|
||||
|
||||
# %%
|
||||
addr = Address("Teststraße", 202, "09111", "Chemnitz")
|
||||
# %%
|
||||
addr.export()
|
||||
# %%
|
||||
Reference in New Issue
Block a user