python ast.literal_eval and datetime

后端 未结 6 1357
终归单人心
终归单人心 2020-12-09 18:26

I have a string \"{\'datetime\': datetime.datetime(2010, 11, 21, 0, 56, 58)}\" and I want to convert this to the object it represents. Using ast.literal_

6条回答
  •  不知归路
    2020-12-09 19:23

    Use the language services to compile it into an AST, walk the AST making sure that it contains only whitelisted node sets, then execute it.

提交回复
热议问题