Attribute and method calling - Utilities

Skip to content
Back to top
View this page
Edit this page

# 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` – string of the name of the method you want to call

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

  EXAMPLES:

  Sage

      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]]

  Python

      >>> 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)

  Call the method `name` on `obj`.

  This has to exist somewhere in Python!!!

  See also

  `operator.methodcaller()` `attrcal()`

  EXAMPLES:

  Sage

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

  Python

      >>> from sage.all import *
      >>> from sage.misc.call import call_method
      >>> call_method(Integer(1), "__add__", Integer(2))
      3