Alan aka David Isaac wrote: > "Peter Otten" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> You are in for a surprise here: > > You got that right! > >> >>> def empty(): >> ... for item in []: >> ... yield item >> ... >> >>> bool(empty()) >> True > > Ouch. > >> >>> bool(iter([])) >> True # python 2.3 and probably 2.5 >> >> >>> bool(iter([])) >> False # python 2.4 > > Double ouch. > I was relying on Python 2.4 behavior. > What is the reasoning behind the changes? > (Can you offer a URL to a discussion?)
Raymond Hettinger introduced an optimization that looked cool until it broke some of Guido's code, see http://mail.python.org/pipermail/python-dev/2005-September/056594.html > So, is the only way to test for an empty iterable > to see if it can generate an item? I found this: > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/413614 > Seems like a reason to rely on sequences ... I'd rather have a second look whether the test is really needed. Peter -- http://mail.python.org/mailman/listinfo/python-list