向python对象动态添加方法 发表于 2016-08-06 | 1234567891011121314def barFighters( self ): print "barFighters"a.barFighters = barFightersa.barFighters()Traceback (most recent call last): File "<stdin>", line 1, in <module>TypeError: barFighters() takes exactly 1 argument (0 given)import typesa.barFighters = types.MethodType( barFighters, a )a.barFighters()barFighters > 引用:http://stackoverflow.com/questions/972/adding-a-method-to-an-existing-object-instance