Created
June 6, 2018 11:17
-
-
Save SebDeclercq/21191ee30bda7678308dc23b8a9be456 to your computer and use it in GitHub Desktop.
Essai pour voir si c'est faisable pour CHBO
This file contains hidden or 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
| #!/usr/bin/env python3 | |
| class Struct(): pass | |
| def toObject(dictionnaire): | |
| object = Struct() | |
| for nom, element in dictionnaire.items(): | |
| if isinstance(element, dict): | |
| setattr(object, nom, toObject(element)) | |
| else: | |
| setattr(object, nom, element) | |
| return object | |
| d = {'az': {'er': 123, 'ty': 456}, 'ui': 789, 'op': {'qs': 12}} | |
| s = toObject(d) | |
| print(s.az.ty) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment