How do I execute a string containing Python code in Python?

后端 未结 14 2575
一向
一向 2020-11-22 02:42

How do I execute a string containing Python code in Python?

14条回答
  •  故里飘歌
    2020-11-22 03:09

    eval() is just for expressions, while eval('x+1') works, eval('x=1') won't work for example. In that case, it's better to use exec, or even better: try to find a better solution :)

提交回复
热议问题