Boolean value of generators

Tony tony10 at ximera.net
Thu Oct 14 11:16:20 CEST 2010


I have been using generators for the first time and wanted to check for
an empty result.  Naively I assumed that generators would give
appopriate boolean values.  For example

def xx():
  l = []
  for x in l:
    yield x

y = xx()
bool(y)


I expected the last line to return False but it actually returns True.
Is there anyway I can enhance my generator or iterator to have the
desired effect?

Regards

Tony Middleton.



More information about the Python-list mailing list