开发者

Data Binding / Data Conversion in Python

Is there a Python lib to convert a bunch of strings to appropriate objects?

Web frameworks represent request data typically as map of the form { st开发者_开发知识库r : [str, ..]} and I want to apply these string data structure to domain objects like Grails does:

def book = new Book(params) // params is from the request

or

book.properties = params


The example you show looks similar to JSON (see e.g. the json python module).

Quoting an example from its documentation:

import json
json.loads('["foo", {"bar":["baz", null, 1.0, 2]}]')

gives you a nested structure of lists/dicts:

[u'foo', {u'bar': [u'baz', None, 1.0, 2]}]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜