Ethan Furman wrote:
Arnaud Delobelle wrote:
I missed the start of this discussion but there are two simpler ways:
def func(iterable):
for x in iterable:
print(x)
return
raise ValueError("... empty iterable")
For the immediate case this is a cool solution.
Drat -- I have to take that back -- the OP stated:
> The intention is:
>
> * detect an empty iterator by catching StopIteration;
> * if the iterator is empty, raise a ValueError;
> * otherwise process the iterator.
Presumably, the print(x) would be replaced with code that processed the
entire iterable (including x, of course), and not just its first element.
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list