Skip to content

Instantly share code, notes, and snippets.

@airtonzanon
Last active April 28, 2020 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save airtonzanon/f40afe03be15bc7acdb42c877d2e003d to your computer and use it in GitHub Desktop.
Save airtonzanon/f40afe03be15bc7acdb42c877d2e003d to your computer and use it in GitHub Desktop.
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