Python how convert single quotes to double quotes to format as json string

后端 未结 3 1315
粉色の甜心
粉色の甜心 2021-01-18 11:13

I have a file where on each line I have text like this (representing cast of a film):

[{\'cast_id\': 23, \'character\': \"Roger \'Verbal\' Kint\", \'credit_i         


        
3条回答
  •  猫巷女王i
    2021-01-18 11:58

    Apart from eval() (mentioned in user3850's answer), you can use ast.literal_eval

    This has been discussed in the thread: Using python's eval() vs. ast.literal_eval()?

    You can also look at the following discussion threads from Kaggle competition which has data similar to the one mentioned by OP:

    https://www.kaggle.com/c/tmdb-box-office-prediction/discussion/89313#latest-517927 https://www.kaggle.com/c/tmdb-box-office-prediction/discussion/80045#latest-518338

提交回复
热议问题