How to remove commas, brackets in python using regular expression?

后端 未结 2 1313
误落风尘
误落风尘 2021-01-24 22:25

These are the contents of my text file (eg:abc.doc):

{\'data\': [{\'name\': \'abc\'},{\'name\': \'xyz\'}]}

After opening the file in python; h

2条回答
  •  伪装坚强ぢ
    2021-01-24 22:40

    Looks to me like you have json, which can be easily parsed using pyjson:

    import json
    obj=json.loads(u'''{'data': [{'name': 'abc'},{'name': 'xyz'}]}''')
    

    Bob's your uncle now, innit?

提交回复
热议问题