Suppose the code below:
from functools import partial
import random
def integer(min=1, max=10):
return random.randint(min, max)
def double(min=1, max=10):
return random.uniform(min, max)
if __name__ == '__main__':
p1 = partial(integer, 5, 10)
p2 = partial(double, 5, 10)
for f in [p1, p2]:
f() # I'd like to know if there's a different way to call this like `call(f)` or something
As mentioned in the comment, I'd like to know if there's a way to call f without using parentheses. One step further, suppose I can call f without using parentheses, if I would like to pass additional parameters to f, how do I go about it (like call(f, additional_param_1, additional_param_2))?
Thank you in advance for your answers!
f.__call__()but I doubt that's what you're after. Why do you want to be able to docall(f, arg1, arg2)? What problem are you really trying to solve, because there probably is a way that doesn't involve acall()function - although you could write such a function quite easily yourself.p1 = partial(integer, 5, 10)applyfunction in Python 2, but even then it was considered obsolete probably decades ago. Why would you ever need this?