Created
January 16, 2018 07:24
-
-
Save fereria/18f008fbc2ea297122ba64a375f391a2 to your computer and use it in GitHub Desktop.
Dictをいい感じに整形して val.param 形式にしてくれる
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
# -*- coding: utf-8 -*- | |
# Dictをいい感じに整形して val.param 形式にしてくれる | |
# 参考 https://stackoverflow.com/questions/6578986/how-to-convert-json-data-into-a-python-object | |
import json | |
from collections import namedtuple | |
data = {"name": "John Smith", "hometown": {"name": "New York", "id": 123}} | |
func = lambda d: namedtuple('X', d.keys())(*d.values()) | |
print func(data) | |
# X(hometown={'name': 'New York', 'id': 123}, name='John Smith') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment