【发布时间】:2018-06-12 21:46:36
【问题描述】:
根据我的研究,我了解到使用getattr() 可以让人们在某个对象上获取方法,例如:
getattr(obj, method)
等价于
obj.method()
但是,我尝试在我的代码中使用它并且语句返回一个内存位置:
<bound method _Class.method of <Class instance at 0x7f412df0c320>>
我不明白我做错了什么。任何帮助表示赞赏。
【问题讨论】:
-
getattr(obj, 'method')相当于obj.method。没有调用任何内容,您只是在检索属性。
标签: python memory getattr getattribute