Using python's eval() vs. ast.literal_eval()?

前端 未结 6 1260
情深已故
情深已故 2020-11-21 06:39

I have a situation with some code where eval() came up as a possible solution. Now I have never had to use eval() before but, I have come across p

6条回答
  •  闹比i
    闹比i (楼主)
    2020-11-21 07:23

    If all you need is a user provided dictionary, possible better solution is json.loads. The main limitation is that json dicts requires string keys. Also you can only provide literal data, but that is also the case for literal_eval.

提交回复
热议问题