【发布时间】:2020-06-07 20:46:37
【问题描述】:
我正在尝试继承numpy.ndarray,但需要在方法中调整数组的大小,但目前没有答案:
Resize inherited ndarray, inside a method?
所以我的问题是如何将方法重定向到本地对象。 对于属性,您可以使用 __getattribute__,__getattr__ 是否有类似的方法选项?
类似这样的:
class Blah():
def __init__(...):
......
self.obj = np.zeros(...)
def __get_method__(self, method):
return self.obj.method() ????
【问题讨论】:
-
方法(或者更确切地说,产生它们的函数)是属性。
__getattr__仅用于通过正常查找过程找不到的属性,而不是用于拦截现有属性。
标签: python redirect methods subclass