Created
March 29, 2019 02:21
-
-
Save craigtracey/95b0a6e0549af30082bd522191aa0fae to your computer and use it in GitHub Desktop.
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 CustomObject(object): | |
@classmethod | |
def from_dict(cls, obj): | |
local_dict = {} | |
for a, v in obj.items(): | |
if isinstance(v, dict): | |
local_dict[a] = cls._attribute_types[a][0].from_dict(v) | |
elif isinstance(v, list): | |
subtype = cls._attribute_types[a][1] | |
ret = [] | |
for i in v: | |
ret.append(subtype(**i)) | |
local_dict[a] = ret | |
else: | |
local_dict[a] = cls._attribute_types[a][0](v) | |
return cls(**local_dict) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment