class iteration_utilities.partial(func, *args, **kwargs)

Like functools.partial() but supporting placeholders.

New in version 0.4.0.


The function to partially wrap.

argsany type

The positional arguments for func.


Using partial._ as one or multiple positional arguments will be interpreted as placeholder that need to be filled when the partial instance is called.

kwargsany type

The keyword arguments for func.


The func where the given positional arguments are fixed (or represented as placeholders) and with optional keyword arguments.


While placeholders can be used for the args they can’t be used for the keywords.


The iteration_utilities.partial can be used as slightly slower drop-in replacement for functools.partial(). However it offers the possibility to pass in placeholders as positional arguments. This can be especially useful if a function does not allow keyword arguments:

>>> from iteration_utilities import partial
>>> isint = partial(isinstance, partial._, int)
>>> isint(10)
>>> isint(11.11)

In this case the isint function is equivalent but faster than lambda x: isinstance(x, int). The partial._ attribute or the Placeholder can be used as placeholders for the positional arguments.

For example most iterators in iteration_utilities take the iterable as the first argument so other arguments can be easily added:

>>> from iteration_utilities import accumulate, Placeholder
>>> from operator import mul
>>> cumprod = partial(accumulate, Placeholder, mul)
>>> list(cumprod([1,2,3,4,5]))
[1, 2, 6, 24, 120]
__call__(*additional_args, **additional_kwargs)

Returns func(*all_args, **all_kwargs) using func. The all_args are the args combined with the additional_args. Likewise the all_kwargs is a mapping created from the keywords with the additional_kwargs.


Returns size of the instance in memory, in bytes.


(Placeholder) Allows easy access to a placeholder without having to import Placeholder.


(dict) instances have a normal __dict__ member and support instance attributes.


(tuple) arguments for future partial calls (readonly).


(callable) Function object to use in future partial calls (readonly).


(dict) keyword arguments for future partial calls (readonly).


(int) Number of placeholders in the args (readonly).