Python中如何对子类的对象调用unbound方法

Python中如何对子类的对象调用unbound方法,python,inheritance,reflection,Python,Inheritance,Reflection,我在Python 2.7中有以下类: class Parent(): def some_method(self): do_something() class Child(Parent): def some_method(self): do_something_different() 假设我有一堆我想运行some\u method的对象。我执行以下几行(前两行是为了本例): 是否存在这样的构造,即在最后一行中调用do_different(),而不

我在Python 2.7中有以下类:

class Parent():
    def some_method(self):
        do_something()

class Child(Parent):
    def some_method(self):
        do_something_different()
假设我有一堆我想运行
some\u method
的对象。我执行以下几行(前两行是为了本例):


是否存在这样的构造,即在最后一行中调用
do_different()
,而不使用有关
子对象的任何信息(因为我可能有许多这样的类继承自
父对象
)?

而不是使用未绑定的方法对象,请使用
操作符.methodcaller

import operator

m = operator.methodcaller('some_method')

m(c)

这将查找对象的实际
some_method
方法并调用它。它更贵,但额外的时间都花在了做你需要的事情上。

这非常接近我的需要!如果我只能访问unbound方法,而不能访问其名称,有没有办法做到这一点?找到它,只需调用
m.\uuuuuu name\uuuu
@Nibor:请注意,
\uuu name\uuuu
可能与属性名称不匹配
Foo.bar
可能有一个
\uuu名称\uuuu
eggs
。一个方法对象没有访问属性名称的权限,因此,如果你只有这个方法对象,那么在所有情况下都不可能做到这一点。好的,我可以重写代码,只保留名称本身。谢谢
import operator

m = operator.methodcaller('some_method')

m(c)