Skip to content

Instantly share code, notes, and snippets.

@KentaYamada
Created December 8, 2019 03:17
Show Gist options
  • Save KentaYamada/dbcb49404d936ffbae9a1463355b33f3 to your computer and use it in GitHub Desktop.
Save KentaYamada/dbcb49404d936ffbae9a1463355b33f3 to your computer and use it in GitHub Desktop.
Mapping dictionary to object
class CarMaker:
def __init__(self, id=None, name=''):
self.id = id
self.name = name
dict_car_maker = {
'id': 1,
'name': 'toyota'
}
car_maker = CarMaker(**dict_car_maker)
print('ID: {0}, Name: {1}'.format(car_maker.id, car_maker.name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment