attribute lookup str and objects like object.myvar

两盒软妹~` 提交于 2019-12-02 14:01:12

I'm guessing you are looking for getattr:

print getattr(myobject, some_dumb_field)

This will look up the attribute of myobject whose name is given by the string some_dumb_field.

For example,

getattr(myobject, 'name')

is equivalent to

myobject.name

(Warning: This could be called attribute lookup; you won't find it under the term "concat".)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!