itertools.izip brokeness
Steven D'Aprano
steve at REMOVETHIScyber.com.au
Fri Jan 6 04:46:11 EST 2006
On Thu, 05 Jan 2006 23:52:13 -0800, Paul Rubin wrote:
> rurpy at yahoo.com writes:
>> def izip4(*iterables, **kw):
>> """kw:fill. An element that will pad the shorter iterable
>> kw:infinite. Number of non-terminating iterators """
>
> That's a really kludgy API. I'm not sure what to propose instead:
> maybe some way of distinguishing which iterables are supposed to be
> iterated til exhaustion (untested):
>
> class Discardable(object): pass
>
> def izip5(*iterables, fill=None):
Doesn't work: keyword arguments must be listed before * and ** arguments.
>>> def izip5(*iterables, fill=None):
File "<stdin>", line 1
def izip5(*iterables, fill=None):
^
SyntaxError: invalid syntax
Personally, I don't see anything wrong with an API of
function(*iterators [, fill]):
Perform function on one or more iterators, with an optional fill
object.
Of course, this has to be defined in code as:
def function(*iterators, **kwargs):
if kwargs.keys() != ["fill"]:
raise ValueError
...
It might not be the easiest API to extend, but for a special case like
this, I think it is perfectly usable.
--
Steven.
More information about the Python-list
mailing list