I have the following simple example code:
def wrapper(foo, para1=1, *args):
print("para1: "+ str(para1))
print(foo(*args))
def foo1(x):
return 2*x
wrapper(foo1, 2, 3)
where I define a function wrapper
that has one parameter para1
with default value 1
.
But in order to call the wrapper with function foo1
correctly, I have to set para1
all the time, because I have to pass the extra arguments to foo1
. That means the default value para1=1
does not make any sense, as I have to define it all the time anyway.
Or is there some other way to define the functions so I can easilz make use of this default value without to have to define it all the time?
For example,
wrapper(foo1, *args=(3,))
wrapper(foo=foo1, args=(3,))
does not work ...
Use case example:
def wrapper(foo, timeout=10, *args):
time0 = time.time()
while time0 < time.time() + timeout:
if foo(*args):
return True
time.sleep(1)
raise SomeTimeout Exception