网站介绍:文章浏览阅读189次。Intro有时候,需要把字符串当做代码执行,看个例子getattrGet a named attribute from an object; getattr(x, ‘y’) is equivalent to x.yimport pandas as pddf=pd.DataFrame({"x":[1,2,3]})getattr(df,"x").count()3getattr(df,“x”)相当于df.x如果想执行df.x*2怎么弄?evaleval("df.x*2")0 _python 把字符串当成代码执行
- 链接地址:https://blog.csdn.net/wendaomudong_l2d4/article/details/122482808
- 链接标题:PythonNote034---把字符串当做代码执行_python 把字符串当成代码执行-CSDN博客
- 所属网站:blog.csdn.net
- 被收藏次数:5012
- 网站标签:python 把字符串当成代码执行