Skip to content

Instantly share code, notes, and snippets.

@craigtracey
Created March 29, 2019 02:21
Show Gist options
  • Save craigtracey/95b0a6e0549af30082bd522191aa0fae to your computer and use it in GitHub Desktop.
Save craigtracey/95b0a6e0549af30082bd522191aa0fae to your computer and use it in GitHub Desktop.
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