using python to parse colon (:) delimited string to an object

前端 未结 4 1803
臣服心动
臣服心动 2021-01-20 16:29

i have a string which is a return value of REST API (http://requesttracker.wikia.com/wiki/REST) and is using colon seperated key/value pairs.

id: 123414
nam         


        
4条回答
  •  不知归路
    2021-01-20 17:07

    That looks like YAML. Have you tried PyYAML?

    >>> import yaml
    >>> s = """id: 123414
    ... name: Peter
    ... message: bla bla
    ...   bla bla"""
    >>> yaml.load(s)
    {'message': 'bla bla bla bla', 'id': 123414, 'name': 'Peter'}
    

提交回复
热议问题