PyDocs

Nav

Functional Programming Modules

partialmethod

functools

class · Added in 3.4 (source)
  • partialmethod(func, /, *args, **keywords)
Method descriptor with partial application of the given arguments
and keywords.

Supports wrapping existing descriptors and handles non-descriptor
callables as instance methods.
1 Example
>>> class Cell:
...     def __init__(self):
...         self._alive = False
...     @property
...     def alive(self):
...         return self._alive
...     def set_state(self, state):
...         self._alive = bool(state)
...     set_alive = partialmethod(set_state, True)
...     set_dead = partialmethod(set_state, False)
...
>>> c = Cell()
>>> c.alive
False
>>> c.set_alive()
>>> c.alive
True
from the Python docs
See Also
No see-alsos for functools/partialmethod
0 Notes
No notes for partialmethod