Message194697
> This would require you to provide at least two elements
I see
how about "def repeatfunc(func, *args, times=None):" ?
>>> from itertools import starmap, repeat
>>>
>>> def repeatfunc(func, *args, times=None):
... """Repeat calls to func with specified arguments.
...
... Example: repeatfunc(random.random)
... """
... if times is None:
... return starmap(func, repeat(args))
... return starmap(func, repeat(args, times))
...
>>> def f(*args):
... print(args)
...
>>> r = repeatfunc(f, 1, 2)
>>> next(r)
(1, 2)
>>> next(r)
(1, 2)
>>> next(r)
(1, 2)
>>> r = repeatfunc(f, 1, 2, times=1)
>>> next(r)
(1, 2)
>>> next(r)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration
>>> |
|
Date |
User |
Action |
Args |
2013-08-08 17:19:55 | py.user | set | recipients:
+ py.user, rhettinger, eric.smith, ezio.melotti, docs@python |
2013-08-08 17:19:55 | py.user | set | messageid: <1375982395.16.0.456474414957.issue18313@psf.upfronthosting.co.za> |
2013-08-08 17:19:55 | py.user | link | issue18313 messages |
2013-08-08 17:19:55 | py.user | create | |
|