Attribute and method calling#

class sage.misc.call.AttrCallObject(name, args, kwds)#

Bases: object

sage.misc.call.attrcall(name, *args, **kwds)#

Return a callable which takes in an object, gets the method named name from that object, and calls it with the specified arguments and keywords.

INPUT:

  • name - a string of the name of the method you want to call

  • args, kwds - arguments and keywords to be passed to the method

EXAMPLES:

sage: f = attrcall('core', 3); f
*.core(3)
sage: [f(p) for p in Partitions(5)]                                             # needs sage.combinat
[[2], [1, 1], [1, 1], [3, 1, 1], [2], [2], [1, 1]]
sage.misc.call.call_method(obj, name, *args, **kwds)#

Call the method name on obj.

This has to exist somewhere in Python!!!

See also

operator.methodcaller() attrcal()

EXAMPLES:

sage: from sage.misc.call import call_method
sage: call_method(1, "__add__", 2)
3