Status of PEPs?
Ville Vainio
ville at spammers.com
Fri Jul 2 11:45:55 EDT 2004
>>>>> "Duncan" == Duncan Booth <me at privacy.net> writes:
Duncan> Or for those of a less masochistic inclination, just use a
Duncan> for loop:
Duncan> for a in iter(getobject, None):
Cute. For those too lazy to check:
iter(callable, sentinel) -> iterator
Get an iterator from an object. In the first form, the argument
must supply its own iterator, or be a sequence.
In the second form, the callable is called until it returns the
sentinel.
(I bet many, including me, haven't heard of this).
It kinda loses some of its appeal when getobject() takes arguments,
though - you'll have to go for lambda then:
for a in iter(lambda : getobject(2,"hi"), None):
--
Ville Vainio http://tinyurl.com/2prnb
More information about the Python-list
mailing list