How to do this in Python? - A "gotcha"
S Arrowsmith
sion at paintbox.UUCP
Wed Mar 18 12:23:05 EDT 2009
Jim Garrison <jhg at acm.org> wrote:
>It's a shame the iter(o,sentinel) builtin does the
>comparison itself, instead of being defined as iter(callable,callable)
>where the second argument implements the termination test and returns a
>boolean. This would seem to add much more generality... is
>it worthy of a PEP?
class sentinel:
def __eq__(self, other):
return termination_test()
for x in iter(callable, sentinel()):
...
Writing a sensible sentinel.__init__ is left as an exercise....
--
\S
under construction
More information about the Python-list
mailing list