python - Python 中的这个(简单?)表达式是什么意思?功能( self )(*参数)

标签 python getattr

<分区>

我看到一些 Python 代码,例如:getattr(self, that)(*args)。这是什么意思?我看到调用了内置的 getattr 函数,传递了当前对象和 that;但是 (*args) 在那之后做了什么?它是否以 *args 作为参数调用某些东西?

最佳答案

你是对的。 that 将成为对象方法的名称。 getattr() 返回该方法(函数)然后调用它。因为函数是一流的成员,所以它们可以传递、返回等。

关于python - Python 中的这个(简单?)表达式是什么意思?功能( self )(*参数),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6335676/

相关文章:

python - 有什么方法可以覆盖 Python 中任意对象的双下划线(魔术)方法吗?

python - 从字符串中获取类对象

python - 点云与python中另一个点云的最佳拟合

python - 如何在不卡住主 UI 的情况下更新 QStandardItemModel

python - python中a值<0时如何停止循环

python - 在python中获取类和实例的属性

使用自定义 __getattr__ 和 __setattr__ 的 Python 深度复制

python - 现在要将此字符串转换为 Python 或 Django 中的日期时间对象?

python - 替换 numpy 数组中多个元素的最快方法

python - 属性错误 : undesired interaction between @property and __getattr__