On Dec 19, 2007 3:18 AM, Realazy XA Chen <[EMAIL PROTECTED]> wrote:
>
> it seems that iterbetter object is always be True even though it has
> not any item in in. so i just wondering if iterbetter object is empty,
> can web.py return a False for me? that will be very useful.

IterBetter's behavior matches that of normal Python iterators:

>>> bool(iter([]))
True

There's no way that an iterator can know whether it's empty or not -
by definition it reads from its source lazily.

> and now I also want to know how to detect an iterbetter object empty
> or not? currently I use try.

Like most questions about IterBetter, the solution to this one is to
turn it into a list:

my_list = list(my_iter)
if my_list:
    do_stuff_with(my_list)
else:
    print 'empty!'

-- 
Gary
http://blog.extracheese.org

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to