Attribute and method calling#

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

Bases: object

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

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]]
>>> from sage.all import *
>>> f = attrcall('core', Integer(3)); f
*.core(3)
>>> [f(p) for p in Partitions(Integer(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)[source]#

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
>>> from sage.all import *
>>> from sage.misc.call import call_method
>>> call_method(Integer(1), "__add__", Integer(2))
3