Last active
April 28, 2020 21:03
-
-
Save airtonzanon/f40afe03be15bc7acdb42c877d2e003d to your computer and use it in GitHub Desktop.
Create named construct with python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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