Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create named construct with python
class NamedConstructor:
def __init__(self,
name: str,
age: int):
self.name = name
self.age = age
def create_person_from_dict(person_data: dict):
return NamedConstructor(
name = person_data['name'],
age = person_data['age']
)
test = NamedConstructor.create_person_from_dict({'name': 'Airton', 'age': 24})
print(test.name)
## Airton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment