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

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

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

14条回答
  •  迷失自我
    2020-11-22 02:49

    You accomplish executing code using exec, as with the following IDLE session:

    >>> kw = {}
    >>> exec( "ret = 4" ) in kw
    >>> kw['ret']
    
    4
    

提交回复
热议问题